Skip to content

Commit

Permalink
fix threading
Browse files Browse the repository at this point in the history
  • Loading branch information
TECH7Fox committed May 4, 2024
1 parent c8989ed commit f4a04a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions custom_components/asterisk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions custom_components/asterisk/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions custom_components/asterisk/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f4a04a8

Please sign in to comment.