diff --git a/custom_components/asterisk/__init__.py b/custom_components/asterisk/__init__.py index 8a63086..8f4992a 100644 --- a/custom_components/asterisk/__init__.py +++ b/custom_components/asterisk/__init__.py @@ -53,10 +53,10 @@ def devices_complete(event: Event, **kwargs): if sip_loaded and pjsip_loaded: _LOGGER.debug("Both SIP and PJSIP loaded. Loading platforms.") - for component in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, component) - ) + asyncio.run_coroutine_threadsafe( + hass.config_entries.async_forward_entry_setups(entry, PLATFORMS), + hass.loop + ) async def send_action_service(call) -> None: "Send action service." diff --git a/custom_components/asterisk/binary_sensor.py b/custom_components/asterisk/binary_sensor.py index 48263e8..283f0b5 100644 --- a/custom_components/asterisk/binary_sensor.py +++ b/custom_components/asterisk/binary_sensor.py @@ -46,7 +46,7 @@ def handle_state_change(self, event: Event, **kwargs): """Handle an device state change event.""" state = event["State"] self._state = state != "UNAVAILABLE" and state != "UNKNOWN" - self.async_write_ha_state() + self.schedule_update_ha_state() @property def is_on(self) -> bool: @@ -81,12 +81,12 @@ def on_disconnect(self, client, response): _LOGGER.debug(f"Disconnected from AMI: {response}") client.disconnect() self._state = False - self.async_write_ha_state() + self.schedule_update_ha_state() def on_reconnect(self, client, response): _LOGGER.debug(f"Reconnected to AMI: {response}") self._state = True - self.async_write_ha_state() + self.schedule_update_ha_state() @property def device_info(self): diff --git a/custom_components/asterisk/sensor.py b/custom_components/asterisk/sensor.py index dd9a5df..4a0e48b 100644 --- a/custom_components/asterisk/sensor.py +++ b/custom_components/asterisk/sensor.py @@ -45,7 +45,7 @@ def handle_event(self, event: Event, **kwargs): """Handle an endpoint update event.""" state = event["State"] self._state = STATES.get(state, STATES["UNKNOWN"]) - self.async_write_ha_state() + self.schedule_update_ha_state() @property def state(self) -> str: @@ -106,7 +106,7 @@ def handle_new_connected_line(self, event: Event, **kwargs): "Exten": event["Exten"], "Context": event["Context"], } - self.async_write_ha_state() + self.schedule_update_ha_state() def handle_hangup(self, event: Event, **kwargs): """Handle an Hangup event.""" @@ -125,7 +125,7 @@ def handle_hangup(self, event: Event, **kwargs): "Cause": event["Cause"], "Cause-txt": event["Cause-txt"], } - self.async_write_ha_state() + self.schedule_update_ha_state() def handle_new_channel(self, event: Event, **kwargs): """Handle an NewChannel event.""" @@ -141,7 +141,7 @@ def handle_new_channel(self, event: Event, **kwargs): "Exten": event["Exten"], "Context": event["Context"], } - self.async_write_ha_state() + self.schedule_update_ha_state() @property def state(self) -> str: @@ -192,7 +192,7 @@ def handle_dtmf(self, event: Event, **kwargs): "ConnectedLineName": event["ConnectedLineName"], "Context": event["Context"], } - self.async_write_ha_state() + self.schedule_update_ha_state() @property def state(self) -> str: @@ -236,7 +236,7 @@ def handle_dtmf(self, event: Event, **kwargs): "ConnectedLineName": event["ConnectedLineName"], "Context": event["Context"], } - self.async_write_ha_state() + self.schedule_update_ha_state() @property def state(self) -> str: