Publish attributes unconditionally (#14179)

* Publish attributes unconditionally

Because the attribute publish command was previously hidden behind `if val:`, falsy values like False and 0.0 weren't being published, thereby making Statestream -- particularly in the case of booleans, where the first True would be retained indefinitely -- a completely worthless indicator of state.

* Change bool test to False to confirm falsy values pass
This commit is contained in:
blackwind 2018-05-05 07:31:39 -06:00 committed by Paulus Schoutsen
parent 5ade84d75f
commit ec3ce4c80d
2 changed files with 5 additions and 6 deletions

View file

@ -88,7 +88,6 @@ def async_setup(hass, config):
if publish_attributes:
for key, val in new_state.attributes.items():
if val:
encoded_val = json.dumps(val, cls=JSONEncoder)
hass.components.mqtt.async_publish(mybase + key,
encoded_val, 1, True)

View file

@ -134,7 +134,7 @@ class TestMqttStateStream(object):
test_attributes = {
"testing": "YES",
"list": ["a", "b", "c"],
"bool": True
"bool": False
}
# Set a state of an entity
@ -150,7 +150,7 @@ class TestMqttStateStream(object):
1, True),
call.async_publish(self.hass, 'pub/fake/entity/list',
'["a", "b", "c"]', 1, True),
call.async_publish(self.hass, 'pub/fake/entity/bool', "true",
call.async_publish(self.hass, 'pub/fake/entity/bool', "false",
1, True)
]