Added scanning possibility to zigbe2mqtt through Hal
This commit is contained in:
parent
1f40d4b1f2
commit
b9168e117f
1 changed files with 26 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2020 Ziver Koc
|
* Copyright (c) 2020-2025 Ziver Koc
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
@ -44,11 +44,12 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class HalMqttController implements HalAutostartController, MqttSubscriptionListener, HalEventController {
|
public class HalMqttController implements HalAutostartController, MqttSubscriptionListener, HalEventController, HalScannableController {
|
||||||
private final Logger logger = LogUtil.getLogger();
|
private final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
private MqttBroker mqttBroker;
|
private MqttBroker mqttBroker;
|
||||||
|
|
||||||
|
private boolean isScanning = false;
|
||||||
private List<HalMqttDetector> detectors = Collections.emptyList();
|
private List<HalMqttDetector> detectors = Collections.emptyList();
|
||||||
private Map<String, List<HalMqttDeviceConfig>> topics = new HashMap<>();
|
private Map<String, List<HalMqttDeviceConfig>> topics = new HashMap<>();
|
||||||
private List<HalDeviceReportListener> deviceListeners = new CopyOnWriteArrayList<>();
|
private List<HalDeviceReportListener> deviceListeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
@ -139,6 +140,12 @@ public class HalMqttController implements HalAutostartController, MqttSubscripti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle scanning status
|
||||||
|
|
||||||
|
if ("zigbee2mqtt/bridge/response/permit_join".equals(topicName)) {
|
||||||
|
isScanning = Objects.equals("true", new String(data, StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MqttBroker getBroker() {
|
public MqttBroker getBroker() {
|
||||||
|
|
@ -199,4 +206,21 @@ public class HalMqttController implements HalAutostartController, MqttSubscripti
|
||||||
if (!deviceListeners.contains(listener))
|
if (!deviceListeners.contains(listener))
|
||||||
deviceListeners.add(listener);
|
deviceListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isScannable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startScan() {
|
||||||
|
// Start scanning for zigbee2mqtt
|
||||||
|
mqttBroker.publish("zigbee2mqtt/bridge/request/permit_join", "{\"value\": true}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isScanning() {
|
||||||
|
return isScanning;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue