cgarwood / homeassistant-zwave_mqtt

Limited Pre-Release of the new OZW1.6 Z-Wave component. Currently has limited platform support. Check the README for more details.
72 stars 8 forks source link

Handle ozwdaemon restart while HA is running #24

Closed cgarwood closed 4 years ago

cgarwood commented 4 years ago

If Home Assistant is currently running and the OZWDaemon restarts, we'll get a bunch of NODE_ADDED and VALUE_ADDED etc events fired, and the component will try to recreate all of the entities instead of simply updating them.

Need to add checks for if the entity already exists and fire an update instead of trying to recreate.

balloob commented 4 years ago

We should only get NODE_ADDED instead of NODE_UPDATED if there also was a NODE_REMOVED event ?

Fishwaldo commented 4 years ago

Node Added is fired when OZW is starting up. Node New is fired when OZW pairs a new device.

It would be nice if you could handle the Inclusion Button on the zsticks as well so people can do a “offline” inclusion.

Fishwaldo commented 4 years ago

And yes, if OZWDaemon restarts - during the shutdown it should remove the node/value topics etc.

MartinHjelmare commented 4 years ago

If I understand correctly:

  1. OZWDaemon decides to restart
  2. OZWDaemon shuts down and during the shutdown sends NODE_REMOVED event for a node.
  3. OZWDaemon starts and sends NODE_ADDED event for the node.

Since this is then normal behavior for the OZWDaemon, we need to handle this in home assistant, as I assume we don't want to remove nodes as they are represented in Home Assistant just because the OZWDaemon restarts.

In Home Assistant we want to add a node representation both when a NODE_ADDED event and a Node New event is fired, if that node is not yet seen.

Side note: How is the Node New event represented in https://github.com/cgarwood/python-openzwave-mqtt? I don't find it.

Is that correct?

balloob commented 4 years ago

Events are fired as EVENT_INSTANCE_EVENT. Payload is {type: "event_name_from_topic", data: {"event": "data}}. See https://github.com/cgarwood/python-openzwave-mqtt/pull/47

marcelveldt commented 4 years ago

Closed by #93 which will mark entities unavailable when OZW is not in a valid state (e.g. restarting). This can be even improved bt watching the LWT message of the OZW daemon on MQTT so we can also track the MQTT connection or OZW broker to be completely offline (non clean shutdown). A normal/clean shutdown of OZW is catched by the status.,