Fix generic_hygrostat error at startup (#88764)

This commit is contained in:
Denis Shulyaka 2023-03-27 22:22:36 +03:00 committed by GitHub
parent 96698813ef
commit 71b5ccee23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,6 +22,8 @@ from homeassistant.const import (
SERVICE_TURN_ON,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, callback
from homeassistant.helpers import condition
@ -175,6 +177,15 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
async def _async_startup(event):
"""Init on startup."""
sensor_state = self.hass.states.get(self._sensor_entity_id)
if sensor_state is None or sensor_state.state in (
STATE_UNKNOWN,
STATE_UNAVAILABLE,
):
_LOGGER.debug(
"The sensor state is %s, initialization is delayed",
sensor_state.state if sensor_state is not None else "None",
)
return
await self._async_sensor_changed(self._sensor_entity_id, None, sensor_state)
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)