Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions homeassistant/components/mqtt/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,7 @@ def config_schema() -> VolSchemaType:

def _setup_from_config(self, config: ConfigType) -> None:
"""(Re)Setup the entity."""
self._zone_info = None

async def async_set_zone_info(timezone: str) -> None:
self._zone_info = await async_get_time_zone(timezone)
if self._zone_info:
return
_LOGGER.warning(
"Ignoring invalid timezone identifier for entity %s, got '%s'",
self.entity_id,
timezone,
)

if timezone := config.get(CONF_TIMEZONE):
self.hass.async_create_task(async_set_zone_info(timezone))
self._timezone_config = config.get(CONF_TIMEZONE)

self._command_template = MqttCommandTemplate(
config.get(CONF_COMMAND_TEMPLATE),
Expand All @@ -131,6 +118,18 @@ async def async_set_zone_info(timezone: str) -> None:
self._optimistic = optimistic or config.get(CONF_STATE_TOPIC) is None
self._attr_assumed_state = bool(self._optimistic)

async def _async_finish_update_config(self) -> None:
"""Called after added to hass and after discovery update."""
self._zone_info = None
if timezone := self._config.get(CONF_TIMEZONE):
self._zone_info = await async_get_time_zone(timezone)
if not self._zone_info:
Comment thread
epenet marked this conversation as resolved.
_LOGGER.warning(
"Ignoring invalid timezone identifier for entity %s, got '%s'",
self.entity_id,
timezone,
)

@callback
def _handle_state_message_received(self, msg: ReceiveMessage) -> None:
"""Handle receiving state message via MQTT."""
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/mqtt/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ async def async_added_to_hass(self) -> None:
self._update_registry_entity_id = None

await super().async_added_to_hass()
await self._async_finish_update_config()
self._subscriptions = {}
self._prepare_subscribe_topics()
if self._subscriptions:
Expand All @@ -1493,6 +1494,12 @@ async def mqtt_async_added_to_hass(self) -> None:
To be extended by subclasses.
"""

async def _async_finish_update_config(self) -> None:
"""Called after added to hass and after discovery update.

To be extended by subclasses.
"""

async def discovery_update(self, discovery_payload: MQTTDiscoveryPayload) -> None:
"""Handle updated discovery message."""
try:
Expand All @@ -1503,6 +1510,7 @@ async def discovery_update(self, discovery_payload: MQTTDiscoveryPayload) -> Non
self._config = config
self._setup_from_config(self._config)
self._setup_common_attributes_from_config(self._config)
await self._async_finish_update_config()

# Prepare MQTT subscriptions
self.attributes_prepare_discovery_update(config)
Expand Down