Skip to content

Commit

Permalink
add coordinator_check and missing_routers
Browse files Browse the repository at this point in the history
  • Loading branch information
o0shojo0o committed Sep 5, 2023
1 parent f1955e7 commit 023591a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ This adapter allows to control the data points of the devices of a Zigbee2MQTT i
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**

- (o0shojo0o) added state `info.coordinator_check` ([#247](https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/247))
- (o0shojo0o) added state `info.missing_routers` ([#247](https://github.com/o0shojo0o/ioBroker.zigbee2mqtt/issues/247))

### 2.12.0 (2023-09-05)

- (o0shojo0o) added option `Size of the object icons in pixels`
Expand Down
27 changes: 26 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,31 @@
},
"native": {}
},
{
"_id": "info.coordinator_check",
"type": "state",
"common": {
"name": "It checks whether routers are missing from the coordinator's memory.",
"role": "button",
"write": true,
"read": true,
"type": "boolean",
"def": true
},
"native": {}
},
{
"_id": "info.missing_routers",
"type": "state",
"common": {
"name": "Routers missing in the coordinator's memory.",
"type": "json",
"read": true,
"write": false,
"def": []
},
"native": {}
},
{
"_id": "",
"type": "meta",
Expand All @@ -331,4 +356,4 @@
"native": {}
}
]
}
}
1 change: 1 addition & 0 deletions lib/statesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class StatesController {
}
this.adapter.subscribeStates('info.debugmessages');
this.adapter.subscribeStates('info.logfilter');
this.adapter.subscribeStates('info.coordinator_check');
}

async setAllAvailableToFalse() {
Expand Down
4 changes: 4 additions & 0 deletions lib/z2mController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class Z2mController {
return;
}

if (id.endsWith('info.coordinator_check')) {
return { topic: 'bridge/request/coordinator_check', payload: '' };
}

const ieee_address = splitedID[2];
const stateName = splitedID[3];

Expand Down
31 changes: 19 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,20 @@ class Zigbee2mqtt extends core.Adapter {
websocketController = new WebsocketController(this);
const wsClient = websocketController.initWsClient();

wsClient.on('open', () => {
this.log.info('Connect to Zigbee2MQTT over websocket connection.');
});
if (wsClient) {
wsClient.on('open', () => {
this.log.info('Connect to Zigbee2MQTT over websocket connection.');
});

wsClient.on('message', (message) => {
this.messageParse(message);
});
wsClient.on('message', (message) => {
this.messageParse(message);
});

wsClient.on('close', async () => {
this.setStateChanged('info.connection', false, true);
await statesController.setAllAvailableToFalse();
});
wsClient.on('close', async () => {
this.setStateChanged('info.connection', false, true);
await statesController.setAllAvailableToFalse();
});
}
}

async messageParse(message) {
Expand Down Expand Up @@ -180,6 +182,11 @@ class Zigbee2mqtt extends core.Adapter {
break;
case 'bridge/event':
break;
case 'bridge/response/coordinator_check':
if (messageObj.payload && messageObj.payload.data && messageObj.payload.data.missing_routers) {
this.setStateChanged('info.missing_routers', messageObj.payload.data.missing_routers, true);
}
break;
case 'bridge/response/device/remove':
break;
case 'bridge/response/device/options':
Expand Down Expand Up @@ -307,12 +314,12 @@ class Zigbee2mqtt extends core.Adapter {

async onStateChange(id, state) {
if (state && state.ack == false) {
if (id.includes('info.debugmessages')) {
if (id.endsWith('info.debugmessages')) {
logCustomizations.debugDevices = state.val;
this.setState(id, state.val, true);
return;
}
if (id.includes('info.logfilter')) {
if (id.endsWith('info.logfilter')) {
logCustomizations.logfilter = state.val.split(';').filter(x => x); // filter removes empty strings here
this.setState(id, state.val, true);
return;
Expand Down

0 comments on commit 023591a

Please sign in to comment.