mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 11:33:11 -04:00
Send removed attributes and entities to ESPHome as None (#195189)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Paulus Schoutsen
Claude Opus 5.5
parent
0c2c53fb33
commit
cf05315a71
@@ -554,7 +554,15 @@ class ESPHomeManager:
|
||||
new_state = event_data["new_state"]
|
||||
old_state = event_data["old_state"]
|
||||
|
||||
# ESPHome keeps the last value it received, so tell it when the entity
|
||||
# or the attribute is removed. It treats "None" as an unset value.
|
||||
if new_state is None:
|
||||
if old_state is not None and (
|
||||
not attribute or attribute in old_state.attributes
|
||||
):
|
||||
self.cli.send_home_assistant_state(
|
||||
event_data["entity_id"], attribute, "None"
|
||||
)
|
||||
return
|
||||
|
||||
# Only communicate changes to the state or attribute tracked, an entity
|
||||
@@ -569,6 +577,13 @@ class ESPHomeManager:
|
||||
):
|
||||
return
|
||||
|
||||
if attribute and attribute not in new_state.attributes:
|
||||
if old_state is not None:
|
||||
self.cli.send_home_assistant_state(
|
||||
event_data["entity_id"], attribute, "None"
|
||||
)
|
||||
return
|
||||
|
||||
self._send_home_assistant_state(event.data["entity_id"], attribute, new_state)
|
||||
|
||||
@callback
|
||||
|
||||
@@ -1855,10 +1855,32 @@ async def test_state_subscription(
|
||||
mock_client.send_home_assistant_state.reset_mock()
|
||||
hass.states.async_set("binary_sensor.test", "on", {})
|
||||
await hass.async_block_till_done()
|
||||
assert mock_client.send_home_assistant_state.mock_calls == []
|
||||
assert mock_client.send_home_assistant_state.mock_calls == [
|
||||
call("binary_sensor.test", "bool", "None"),
|
||||
call("binary_sensor.test", "float", "None"),
|
||||
]
|
||||
mock_client.send_home_assistant_state.reset_mock()
|
||||
hass.states.async_set("binary_sensor.test", "off", {})
|
||||
await hass.async_block_till_done()
|
||||
assert mock_client.send_home_assistant_state.mock_calls == [
|
||||
call("binary_sensor.test", None, "off")
|
||||
]
|
||||
mock_client.send_home_assistant_state.reset_mock()
|
||||
hass.states.async_remove("binary_sensor.test")
|
||||
await hass.async_block_till_done()
|
||||
assert mock_client.send_home_assistant_state.mock_calls == []
|
||||
assert mock_client.send_home_assistant_state.mock_calls == [
|
||||
call("binary_sensor.test", None, "None")
|
||||
]
|
||||
mock_client.send_home_assistant_state.reset_mock()
|
||||
hass.states.async_set("binary_sensor.test", "on", {"bool": True})
|
||||
await hass.async_block_till_done()
|
||||
mock_client.send_home_assistant_state.reset_mock()
|
||||
hass.states.async_remove("binary_sensor.test")
|
||||
await hass.async_block_till_done()
|
||||
assert mock_client.send_home_assistant_state.mock_calls == [
|
||||
call("binary_sensor.test", None, "None"),
|
||||
call("binary_sensor.test", "bool", "None"),
|
||||
]
|
||||
|
||||
|
||||
async def test_state_subscription_entity_added_later(
|
||||
|
||||
Reference in New Issue
Block a user