mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 10:28:33 -07:00
Don’t create state when cache_state is set to false. #1287
This commit is contained in:
parent
61d85af3fd
commit
5c9b31b2fc
@ -27,7 +27,10 @@ class Controller {
|
||||
constructor() {
|
||||
this.zigbee = new Zigbee();
|
||||
this.mqtt = new MQTT();
|
||||
this.state = new State();
|
||||
|
||||
if (settings.get().advanced.cache_state) {
|
||||
this.state = new State();
|
||||
}
|
||||
|
||||
// Bind methods
|
||||
this.onMQTTConnected = this.onMQTTConnected.bind(this);
|
||||
@ -155,7 +158,9 @@ class Controller {
|
||||
}
|
||||
|
||||
start() {
|
||||
this.state.start();
|
||||
if (this.state) {
|
||||
this.state.start();
|
||||
}
|
||||
|
||||
this.startupLogVersion(() => {
|
||||
this.zigbee.start(this.onZigbeeMessage, (error) => {
|
||||
@ -175,7 +180,10 @@ class Controller {
|
||||
this.extensions.filter((e) => e.stop).forEach((e) => e.stop());
|
||||
|
||||
// Wrap-up
|
||||
this.state.stop();
|
||||
if (this.state) {
|
||||
this.state.stop();
|
||||
}
|
||||
|
||||
this.mqtt.disconnect();
|
||||
this.zigbee.stop(callback);
|
||||
}
|
||||
@ -210,7 +218,7 @@ class Controller {
|
||||
|
||||
sendAllCachedStates() {
|
||||
this.zigbee.getAllClients().forEach((device) => {
|
||||
if (this.state.exists(device.ieeeAddr)) {
|
||||
if (this.state && this.state.exists(device.ieeeAddr)) {
|
||||
this.publishEntityState(device.ieeeAddr, this.state.get(device.ieeeAddr));
|
||||
}
|
||||
});
|
||||
@ -221,7 +229,7 @@ class Controller {
|
||||
const appSettings = settings.get();
|
||||
let messagePayload = {...payload};
|
||||
|
||||
if (appSettings.advanced.cache_state) {
|
||||
if (this.state) {
|
||||
// Add cached state to payload
|
||||
if (this.state.exists(entityID)) {
|
||||
messagePayload = objectAssignDeep.noMutate(this.state.get(entityID), payload);
|
||||
|
@ -205,7 +205,9 @@ class BridgeConfig {
|
||||
settings.removeDevice(deviceID);
|
||||
|
||||
// Remove from state
|
||||
this.state.remove(deviceID);
|
||||
if (this.state) {
|
||||
this.state.remove(deviceID);
|
||||
}
|
||||
|
||||
logger.info(`Successfully ${ban ? 'banned' : 'removed'} ${deviceID}`);
|
||||
this.mqtt.log(ban ? 'device_banned' : 'device_removed', message);
|
||||
|
@ -774,7 +774,7 @@ class HomeAssistant {
|
||||
const timer = setTimeout(() => {
|
||||
// Publish all device states.
|
||||
this.zigbee.getAllClients().forEach((device) => {
|
||||
if (this.state.exists(device.ieeeAddr)) {
|
||||
if (this.state && this.state.exists(device.ieeeAddr)) {
|
||||
this.publishEntityState(device.ieeeAddr, this.state.get(device.ieeeAddr));
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user