1 """Support for buttons."""
3 from __future__
import annotations
5 from homeassistant
import config_entries
14 from .const
import CONF_PROJECT_ID, CONF_SERVICE_ACCOUNT, DATA_CONFIG, DOMAIN
15 from .http
import GoogleConfig
21 async_add_entities: AddEntitiesCallback,
23 """Set up the platform."""
24 yaml_config: ConfigType = hass.data[DOMAIN][DATA_CONFIG]
25 google_config: GoogleConfig = hass.data[DOMAIN][config_entry.entry_id]
29 if CONF_SERVICE_ACCOUNT
in yaml_config:
30 entities.append(
SyncButton(config_entry.data[CONF_PROJECT_ID], google_config))
36 """Representation of a synchronization button."""
38 _attr_has_entity_name =
True
39 _attr_translation_key =
"sync_devices"
41 def __init__(self, project_id: str, google_config: GoogleConfig) ->
None:
42 """Initialize button."""
48 identifiers={(DOMAIN, project_id)},
49 name=
"Google Assistant",
53 """Press the button."""
55 agent_user_id = self.
_google_config_google_config.get_agent_user_id_from_context(
58 result = await self.
_google_config_google_config.async_sync_entities(agent_user_id)
61 f
"Unable to sync devices with result code: {result}, check log for more"