mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
Implement banning devices. #816
This commit is contained in:
parent
84f9d09b3f
commit
35b9e6204d
@ -12,6 +12,7 @@ zigbee2mqtt will output log to this endpoint. Message are always in the form of
|
||||
* `"pairing"`: logging when device is connecting to the network.
|
||||
* `"device_connected"`: send when a new device connects to the network.
|
||||
* `"device_removed"`: send when a device is removed from the network.
|
||||
* `"device_banned"`: send when a device is banned from the network.
|
||||
* `"devices"`: a list of all devices, this message can be triggered by sending a message to `zigbee2mqtt/bridge/config/devices` (payload doesn't matter).
|
||||
|
||||
## zigbee2mqtt/bridge/config/permit_join
|
||||
@ -25,6 +26,9 @@ Allows you to switch the `log_level` during runtime. This is not persistent (wil
|
||||
## zigbee2mqtt/bridge/config/remove
|
||||
Allows you to remove devices from the network. Payload should be the `friendly_name`, e.g. `0x00158d0001b79111`. On successful remove a [`device_removed`](https://koenkk.github.io/zigbee2mqtt/information/mqtt_topics_and_message_structure.html#zigbee2mqttbridgelog) message is send.
|
||||
|
||||
## zigbee2mqtt/bridge/config/ban
|
||||
Allows you to ban devices from the network. Payload should be the `friendly_name`, e.g. `0x00158d0001b79111`. On successful ban a [`device_banned`](https://koenkk.github.io/zigbee2mqtt/information/mqtt_topics_and_message_structure.html#zigbee2mqttbridgelog) message is send.
|
||||
|
||||
## zigbee2mqtt/bridge/config/rename
|
||||
Allows you to change the `friendly_name` of a device on the fly.
|
||||
Format should be: `{"old": "OLD_FRIENDLY_NAME", "new": "NEW_FRIENDLY_NAME"}`.
|
||||
|
@ -18,6 +18,7 @@ class BridgeConfig {
|
||||
this.devices = this.devices.bind(this);
|
||||
this.rename = this.rename.bind(this);
|
||||
this.remove = this.remove.bind(this);
|
||||
this.ban = this.ban.bind(this);
|
||||
|
||||
// Set supported options
|
||||
this.supportedOptions = {
|
||||
@ -26,6 +27,7 @@ class BridgeConfig {
|
||||
'devices': this.devices,
|
||||
'rename': this.rename,
|
||||
'remove': this.remove,
|
||||
'ban': this.ban,
|
||||
};
|
||||
}
|
||||
|
||||
@ -89,6 +91,14 @@ class BridgeConfig {
|
||||
}
|
||||
|
||||
remove(topic, message) {
|
||||
this.removeOrBan(false, message);
|
||||
}
|
||||
|
||||
ban(topic, message) {
|
||||
this.removeOrBan(true, message);
|
||||
}
|
||||
|
||||
removeOrBan(ban, message) {
|
||||
message = message.toString();
|
||||
const IDByFriendlyName = settings.getIeeeAddrByFriendlyName(message);
|
||||
const deviceID = IDByFriendlyName ? IDByFriendlyName : message;
|
||||
@ -101,17 +111,17 @@ class BridgeConfig {
|
||||
// Remove from state
|
||||
this.state.remove(deviceID);
|
||||
|
||||
logger.info(`Successfully removed ${deviceID}`);
|
||||
this.mqtt.log('device_removed', message);
|
||||
logger.info(`Successfully ${ban ? 'banned' : 'removed'} ${deviceID}`);
|
||||
this.mqtt.log(ban ? 'device_banned' : 'device_removed', message);
|
||||
};
|
||||
|
||||
// Remove from zigbee network.
|
||||
if (device) {
|
||||
this.zigbee.removeDevice(deviceID, (error) => {
|
||||
this.zigbee.removeDevice(deviceID, ban, (error) => {
|
||||
if (!error) {
|
||||
cleanup();
|
||||
} else {
|
||||
logger.error(`Failed to remove ${deviceID}`);
|
||||
logger.error(`Failed to ${ban ? 'ban' : 'remove'} ${deviceID}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -137,8 +137,8 @@ class Zigbee {
|
||||
return this.getDevices().filter((device) => device.type !== 'Coordinator');
|
||||
}
|
||||
|
||||
removeDevice(deviceID, callback) {
|
||||
this.shepherd.remove(deviceID, (error) => {
|
||||
removeDevice(deviceID, ban, callback) {
|
||||
this.shepherd.remove(deviceID, {reJoin: !ban}, (error) => {
|
||||
if (error) {
|
||||
logger.warn(`Failed to remove '${deviceID}', trying force remove...`);
|
||||
this.forceRemove(deviceID, callback);
|
||||
|
Loading…
Reference in New Issue
Block a user