From 6775562ada64f37df351fb5dc948914297921f63 Mon Sep 17 00:00:00 2001 From: Alone Date: Mon, 16 Dec 2024 10:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20improve=20for=20coordinato?= =?UTF-8?q?rs=20(#2079)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/xiaomi_miot/core/device.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_components/xiaomi_miot/core/device.py b/custom_components/xiaomi_miot/core/device.py index 24de7525c..e58de1b00 100644 --- a/custom_components/xiaomi_miot/core/device.py +++ b/custom_components/xiaomi_miot/core/device.py @@ -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() @@ -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 = [] @@ -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: @@ -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: