homieiot / convention

🏡 The Homie Convention: a lightweight MQTT convention for the IoT
https://homieiot.github.io/
Other
710 stars 59 forks source link

Add nodes and properties after reaching the ready state #174

Closed EP-u-NW closed 5 years ago

EP-u-NW commented 5 years ago

Is a device allowed to add nodes and properties after going the the ready state? I have not found a passage in the convention that clearly forbbids this. But I'm still not sure, because of this passage:

ready: this is the state the device is in when it is connected to the MQTT broker, has sent all Homie messages and is ready to operate. You have to send this message after all other announcements message have been sent.

I'm not sure if a node or a property counts to the announcements category. If so, the above could imply, that it is forbidden to add new nodes and properties after the device reached the ready state. Also, what would that mean for changing an attribute of a node or property?

Contradicting the above interpreation is @davidgraeff comment in #162. While there it's stated that properties might be unpublished at any time, it also says, that no Homie controller yet supports this.

I'm asking all this, since my dart implementation of Homie currently does not allow to add nodes and properties after creation of a device. Also, attributes can not be changed. Maybe this needs to be reworked.

davidgraeff commented 5 years ago

You could say that a device first have to go a a $state!=ready, republish topics and then back to $state=ready. But an mqtt broker is not required to keep the message order or provide any guarantees about the timing. A topic publishing might take a 1 minute.

That's why I said that it is sufficient to just change the $nodes and $properties and a controller is required to watch those attributes for changes.

EP-u-NW commented 5 years ago

So I conclude that its allowed.

OT: openHAB seems to be the only "complete" controller out there (and you impelemted the binding for it), and it's the one I plan using. How would openHAB react if a Homie device changes it's nodes and properties without changing its state?

davidgraeff commented 5 years ago

The OH mqtt binding subscribes to $nodes and all $properties topics and adapts the tree like in-memory representation of nodes and properties and informs OH about new channels and removed channels.

The mqtt binding cannot handle the situation if only attributes like $name or $unit are changed.

EP-u-NW commented 5 years ago

What if I then add a "void"-property to a node, also list it in the $properties topic and then remove it. Will other changed attributes of the node also be updated?

davidgraeff commented 5 years ago

A node does not have many attributes anyway, mainly $name and $type. And $name is afaik a subscribed topic with changes propagated back to openHAB channel names. If that is not the case I'd consider that a bug.