Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Threading for 2024.5 #99

Merged
merged 6 commits into from
May 4, 2024
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
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
2 changes: 1 addition & 1 deletion custom_components/asterisk/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"loggers": ["custom_components.asterisk"],
"requirements": ["asterisk-ami==0.1.6"],
"ssdp": [],
"version": "1.0.3",
"version": "1.0.4",
"zeroconf": []
}
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
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
asterisk-ami==0.1.6
asterisk-ami==0.1.7
pytest-homeassistant-custom-component
pre-commit
Loading
Loading