Always update attributes on an update for MQTT update (#82139)

This commit is contained in:
Jan Bouwhuis 2022-11-15 18:43:01 +01:00 committed by GitHub
parent ade4b62aec
commit 7932864e00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -196,19 +196,19 @@ class MqttUpdate(MqttEntity, UpdateEntity, RestoreEntity):
self._attr_latest_version = json_payload["latest_version"]
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
if CONF_TITLE in json_payload and not self._attr_title:
if CONF_TITLE in json_payload:
self._attr_title = json_payload[CONF_TITLE]
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
if CONF_RELEASE_SUMMARY in json_payload and not self._attr_release_summary:
if CONF_RELEASE_SUMMARY in json_payload:
self._attr_release_summary = json_payload[CONF_RELEASE_SUMMARY]
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
if CONF_RELEASE_URL in json_payload and not self._attr_release_url:
if CONF_RELEASE_URL in json_payload:
self._attr_release_url = json_payload[CONF_RELEASE_URL]
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)
if CONF_ENTITY_PICTURE in json_payload and not self._entity_picture:
if CONF_ENTITY_PICTURE in json_payload:
self._entity_picture = json_payload[CONF_ENTITY_PICTURE]
get_mqtt_data(self.hass).state_write_requests.write_state_request(self)

View File

@ -203,8 +203,9 @@ async def test_json_state_message(hass, mqtt_mock_entry_with_yaml_config):
hass,
state_topic,
'{"installed_version":"1.9.0","latest_version":"1.9.0",'
'"title":"Test Update Title","release_url":"https://example.com/release",'
'"release_summary":"Test release summary"}',
'"title":"Test Update 1 Title","release_url":"https://example.com/release1",'
'"release_summary":"Test release summary 1",'
'"entity_picture": "https://example.com/icon1.png"}',
)
await hass.async_block_till_done()
@ -213,14 +214,16 @@ async def test_json_state_message(hass, mqtt_mock_entry_with_yaml_config):
assert state.state == STATE_OFF
assert state.attributes.get("installed_version") == "1.9.0"
assert state.attributes.get("latest_version") == "1.9.0"
assert state.attributes.get("release_summary") == "Test release summary"
assert state.attributes.get("release_url") == "https://example.com/release"
assert state.attributes.get("title") == "Test Update Title"
assert state.attributes.get("release_summary") == "Test release summary 1"
assert state.attributes.get("release_url") == "https://example.com/release1"
assert state.attributes.get("title") == "Test Update 1 Title"
assert state.attributes.get("entity_picture") == "https://example.com/icon1.png"
async_fire_mqtt_message(
hass,
state_topic,
'{"installed_version":"1.9.0","latest_version":"2.0.0","title":"Test Update Title"}',
'{"installed_version":"1.9.0","latest_version":"2.0.0",'
'"title":"Test Update 2 Title","entity_picture":"https://example.com/icon2.png"}',
)
await hass.async_block_till_done()
@ -229,6 +232,7 @@ async def test_json_state_message(hass, mqtt_mock_entry_with_yaml_config):
assert state.state == STATE_ON
assert state.attributes.get("installed_version") == "1.9.0"
assert state.attributes.get("latest_version") == "2.0.0"
assert state.attributes.get("entity_picture") == "https://example.com/icon2.png"
async def test_json_state_message_with_template(hass, mqtt_mock_entry_with_yaml_config):