Report unavailable entities to google (#28501)
* Report unavailable entites to google. Entities should only removed when removed from HA. Removing a temporarily unavailable entity from google causes it to need to re-configured once it become available again. * Fix test for unavailable entities
This commit is contained in:
parent
32e04e1dce
commit
4191d9ca8d
2 changed files with 35 additions and 5 deletions
|
@ -336,7 +336,7 @@ class GoogleEntity:
|
|||
@callback
|
||||
def is_supported(self) -> bool:
|
||||
"""Return if the entity is supported by Google."""
|
||||
return self.state.state != STATE_UNAVAILABLE and bool(self.traits())
|
||||
return bool(self.traits())
|
||||
|
||||
@callback
|
||||
def might_2fa(self) -> bool:
|
||||
|
|
|
@ -466,14 +466,17 @@ async def test_serialize_input_boolean(hass):
|
|||
}
|
||||
|
||||
|
||||
async def test_unavailable_state_doesnt_sync(hass):
|
||||
"""Test that an unavailable entity does not sync over."""
|
||||
light = DemoLight(None, "Demo Light", state=False)
|
||||
async def test_unavailable_state_does_sync(hass):
|
||||
"""Test that an unavailable entity does sync over."""
|
||||
light = DemoLight(None, "Demo Light", state=False, hs_color=(180, 75))
|
||||
light.hass = hass
|
||||
light.entity_id = "light.demo_light"
|
||||
light._available = False # pylint: disable=protected-access
|
||||
await light.async_update_ha_state()
|
||||
|
||||
events = []
|
||||
hass.bus.async_listen(EVENT_SYNC_RECEIVED, events.append)
|
||||
|
||||
result = await sh.async_handle_message(
|
||||
hass,
|
||||
BASIC_CONFIG,
|
||||
|
@ -483,8 +486,35 @@ async def test_unavailable_state_doesnt_sync(hass):
|
|||
|
||||
assert result == {
|
||||
"requestId": REQ_ID,
|
||||
"payload": {"agentUserId": "test-agent", "devices": []},
|
||||
"payload": {
|
||||
"agentUserId": "test-agent",
|
||||
"devices": [
|
||||
{
|
||||
"id": "light.demo_light",
|
||||
"name": {"name": "Demo Light"},
|
||||
"traits": [
|
||||
trait.TRAIT_BRIGHTNESS,
|
||||
trait.TRAIT_ONOFF,
|
||||
trait.TRAIT_COLOR_SETTING,
|
||||
],
|
||||
"type": const.TYPE_LIGHT,
|
||||
"willReportState": False,
|
||||
"attributes": {
|
||||
"colorModel": "hsv",
|
||||
"colorTemperatureRange": {
|
||||
"temperatureMinK": 2000,
|
||||
"temperatureMaxK": 6535,
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].event_type == EVENT_SYNC_RECEIVED
|
||||
assert events[0].data == {"request_id": REQ_ID}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue