Skip to content

Commit

Permalink
♻️ improve for coordinators (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 16, 2024
1 parent a4ee76a commit 6775562
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions custom_components/xiaomi_miot/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ async def async_init(self):
self._exclude_miot_properties = self.custom_config_list('exclude_miot_properties', [])
self._unreadable_properties = self.custom_config_bool('unreadable_properties')

if not self.coordinators:
await self.init_coordinators()

async def async_unload(self):
for coo in self.coordinators:
await coo.async_shutdown()
Expand Down Expand Up @@ -444,9 +447,8 @@ async def init_coordinators(self):
DataCoordinator(self, self.update_miio_commands, update_interval=timedelta(seconds=interval)),
)
self.coordinators.extend(lst)
if self.entry.setup_in_progress:
for coo in lst:
await coo.async_config_entry_first_refresh()
for coo in lst:
await coo.async_config_entry_first_refresh()

async def init_miot_coordinators(self, interval=60):
lst = []
Expand Down Expand Up @@ -508,11 +510,11 @@ async def _update():

async def update_status(self):
for coo in self.coordinators:
await coo.async_refresh()
await coo.async_request_refresh()

async def update_main_status(self):
for coo in self.main_coordinators:
await coo.async_refresh()
await coo.async_request_refresh()

def add_entities(self, domain):
for conv in self.converters:
Expand All @@ -536,8 +538,6 @@ def add_entities(self, domain):

if domain == 'button':
self.dispatch_info()
if not self.coordinators:
self.hass.loop.create_task(self.init_coordinators())

def add_entity(self, entity: 'BasicEntity', unique=None):
if unique == None:
Expand Down

0 comments on commit 6775562

Please # to comment.