Google: Report all states on activating report state (#27312)
This commit is contained in:
1 parent
0cfd0388d6
commit
a51e0d7a5f
3 files changed
+54
-6
No files matched your search
@@ -182,6 +182,11 @@ class GoogleEntity:
|
||||
]
|
||||
return self._traits
|
||||
|
||||
@callback
|
||||
def should_expose(self):
|
||||
"""If entity should be exposed."""
|
||||
return self.config.should_expose(self.state)
|
||||
|
||||
@callback
|
||||
def is_supported(self) -> bool:
|
||||
"""Return if the entity is supported by Google."""
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
"""Google Report State implementation."""
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.const import MATCH_ALL
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
|
||||
from .helpers import AbstractConfig, GoogleEntity
|
||||
from .helpers import AbstractConfig, GoogleEntity, async_get_entities
|
||||
|
||||
# Time to wait until the homegraph updates
|
||||
# https://github.com/actions-on-google/smart-home-nodejs/issues/196#issuecomment-439156639
|
||||
INITIAL_REPORT_DELAY = 60
|
||||
|
||||
|
||||
@callback
|
||||
@@ -34,6 +39,23 @@ def async_enable_report_state(hass: HomeAssistant, google_config: AbstractConfig
|
||||
{"devices": {"states": {changed_entity: entity_data}}}
|
||||
)
|
||||
|
||||
async_call_later(
|
||||
hass, INITIAL_REPORT_DELAY, _async_report_all_states(hass, google_config)
|
||||
)
|
||||
|
||||
return hass.helpers.event.async_track_state_change(
|
||||
MATCH_ALL, async_entity_state_listener
|
||||
)
|
||||
|
||||
|
||||
async def _async_report_all_states(hass: HomeAssistant, google_config: AbstractConfig):
|
||||
"""Report all states."""
|
||||
entities = {}
|
||||
|
||||
for entity in async_get_entities(hass, google_config):
|
||||
if not entity.should_expose():
|
||||
continue
|
||||
|
||||
entities[entity.entity_id] = entity.query_serialize()
|
||||
|
||||
await google_config.async_report_state({"devices": {"states": entities}})
|
||||
Reference in new issue
Block a user