Skip to content

Commit

Permalink
Merge pull request #166 from elad-bar/remove-startup-blocking-call
Browse files Browse the repository at this point in the history
remove startup blocking call
  • Loading branch information
elad-bar authored Jun 20, 2024
2 parents 9a3444c + 4e730a6 commit 7ed8833
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add support for `inktank` cartridge type [#162](https://github.com/elad-bar/ha-hpprinter/issues/162)
- Add sensor of total printed pages per consumable, available for toner only [#72](https://github.com/elad-bar/ha-hpprinter/issues/72)
- Fix HTTPS requests [#160](https://github.com/elad-bar/ha-hpprinter/issues/160)
- Remove startup blocking call

## 2.0.2

Expand Down
27 changes: 21 additions & 6 deletions custom_components/hpprinter/managers/ha_coordinator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys

from homeassistant.core import Event
from homeassistant.core import Event, callback
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
Expand Down Expand Up @@ -52,11 +52,7 @@ def __init__(
"Adapter": self.create_adapter_device,
}

self.config_entry.async_on_unload(
async_dispatcher_connect(
hass, SIGNAL_HA_DEVICE_DISCOVERED, self._on_device_discovered
)
)
self._load_signal_handlers()

@property
def api(self) -> RestAPIv2:
Expand Down Expand Up @@ -93,6 +89,25 @@ async def initialize(self):

await self.async_config_entry_first_refresh()

def _load_signal_handlers(self):
loop = self.hass.loop

@callback
def on_device_discovered(
entry_id: str, device_key: str, device_data: dict, device_config: dict
):
loop.create_task(
self._on_device_discovered(
entry_id, device_key, device_data, device_config
)
).__await__()

self.config_entry.async_on_unload(
async_dispatcher_connect(
self.hass, SIGNAL_HA_DEVICE_DISCOVERED, self._on_device_discovered
)
)

def create_main_device(
self, device_key: str, device_data: dict, device_config: dict
):
Expand Down

0 comments on commit 7ed8833

Please sign in to comment.