mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Mark ESPHome update entity unavailable when device is offline (#87576)
This commit is contained in:
@@ -145,3 +145,54 @@ async def test_update_static_info(
|
||||
|
||||
state = hass.states.get("update.none_firmware")
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_update_device_state_for_availability(
|
||||
hass,
|
||||
mock_config_entry,
|
||||
mock_device_info,
|
||||
mock_dashboard,
|
||||
):
|
||||
"""Test ESPHome update entity changes availability with the device."""
|
||||
mock_dashboard["configured"] = [
|
||||
{
|
||||
"name": "test",
|
||||
"current_version": "1.2.3",
|
||||
},
|
||||
]
|
||||
await async_get_dashboard(hass).async_refresh()
|
||||
|
||||
signal_device_updated = f"esphome_{mock_config_entry.entry_id}_on_device_update"
|
||||
runtime_data = Mock(
|
||||
available=True,
|
||||
device_info=mock_device_info,
|
||||
signal_device_updated=signal_device_updated,
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.esphome.update.DomainData.get_entry_data",
|
||||
return_value=runtime_data,
|
||||
):
|
||||
assert await hass.config_entries.async_forward_entry_setup(
|
||||
mock_config_entry, "update"
|
||||
)
|
||||
|
||||
state = hass.states.get("update.none_firmware")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
||||
runtime_data.available = False
|
||||
async_dispatcher_send(hass, signal_device_updated)
|
||||
|
||||
state = hass.states.get("update.none_firmware")
|
||||
assert state.state == "unavailable"
|
||||
|
||||
# Deep sleep devices should still be available
|
||||
runtime_data.device_info = dataclasses.replace(
|
||||
runtime_data.device_info, has_deep_sleep=True
|
||||
)
|
||||
|
||||
async_dispatcher_send(hass, signal_device_updated)
|
||||
|
||||
state = hass.states.get("update.none_firmware")
|
||||
assert state.state == "on"
|
||||
|
||||
Reference in New Issue
Block a user