tim-hellhake / homie-adapter

Mozilla Public License 2.0
0 stars 3 forks source link

Fix/cast values from string #11

Closed mrsteakhouse closed 3 years ago

mrsteakhouse commented 3 years ago

Hey there,

this PR incaludes two changes and affect #10

  1. make sure to cast the incoming value to its configured type, if it was configured earlier.
    • NOTE: The first incoming value is always stored as string. This is beacause MQTT orders the retained messages with the same QoS by subtypes (seperated by /). Less subtypes result in earlier handling of that message. All subsquent messages are handled accordingly to the configured type.
  2. Since Node properties are not validated or set in any matter, we can ignore them for now. I noticed during testing that some of the node's properties were handled as if it were the containing value. This exposed internal information and cluttered the Thing with properties, the user is not interested in.
    • This is only f771fd2

To test this, just add a device with float values:

mosquitto_pub -t 'homie/device/$homie'-m '4.0'
mosquitto_pub -t 'homie/device/$state'-m 'ready'
mosquitto_pub -t 'homie/device/$name'-m 'Temperature'
mosquitto_pub -t 'homie/device/$nodes'-m 'temperature'
mosquitto_pub -t 'homie/device/temperature/$name'-m 'Temperature Node'
mosquitto_pub -t 'homie/device/temperature/$properties'-m 'temp,hum,p'
mosquitto_pub -t 'homie/device/temperature/temp'-m '23.79'
mosquitto_pub -t 'homie/device/temperature/temp/$name'-m 'Temperature Prop'
mosquitto_pub -t 'homie/device/temperature/temp/$unit'-m '°C'
mosquitto_pub -t 'homie/device/temperature/temp/$datatype'-m 'float'
mosquitto_pub -t 'homie/device/temperature/temp/$settable'-m 'false'

The first value will set as string. All subsquent messages are set as Number. This can be observed in the logs, when the device's property is added.

mosquitto_pub -t 'homie/device/temperature/temp'-m '25.79'
tim-hellhake commented 3 years ago

Thank you very much for your contribution! The update should be available soon.