Skip to content

Commit

Permalink
🛜 improve for update status (#2104)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 20, 2024
1 parent 184c990 commit cb8140e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion custom_components/xiaomi_miot/core/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ def decode(self, device: 'Device', payload: dict, value):
'updater': updater or 'none',
'updated_at': str(device.data.get('updated', '')),
}
customizes = {**device.customizes}
customizes.pop('extend_miot_specs', None)
payload.update({
**infos,
**device.props,
'converters': [c.full_name for c in device.converters],
'customizes': device.customizes,
'customizes': customizes,
**infos,
})
if device.available:
Expand Down
10 changes: 8 additions & 2 deletions custom_components/xiaomi_miot/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.const import CONF_HOST, CONF_TOKEN, CONF_MODEL, CONF_USERNAME, EntityCategory
from homeassistant.util import dt
from homeassistant.components import persistent_notification
from homeassistant.helpers.event import async_call_later
import homeassistant.helpers.device_registry as dr

from .const import (
Expand Down Expand Up @@ -458,11 +459,11 @@ async def init_coordinators(self):
lst = await self.init_miot_coordinators(interval)
if self.cloud_statistics_commands:
lst.append(
DataCoordinator(self, self.update_cloud_statistics, update_interval=timedelta(seconds=interval*20)),
DataCoordinator(self, self.update_cloud_statistics, update_interval=timedelta(seconds=interval*10)),
)
if self.miio_cloud_records:
lst.append(
DataCoordinator(self, self.update_miio_cloud_records, update_interval=timedelta(seconds=interval*20)),
DataCoordinator(self, self.update_miio_cloud_records, update_interval=timedelta(seconds=interval*10)),
)
if self.miio_cloud_props:
lst.append(
Expand All @@ -479,6 +480,7 @@ async def init_coordinators(self):
self.coordinators.extend(lst)
for coo in lst:
await coo.async_config_entry_first_refresh()
async_call_later(self.hass, 10, self.update_all_status)

async def init_miot_coordinators(self, interval=60):
lst = []
Expand Down Expand Up @@ -546,6 +548,10 @@ async def update_main_status(self):
for coo in self.main_coordinators:
await coo.async_request_refresh()

async def update_all_status(self, _=None):
for coo in self.coordinators:
await coo.async_request_refresh()

def add_entities(self, domain):
for conv in self.converters:
if conv.domain != domain:
Expand Down
7 changes: 4 additions & 3 deletions custom_components/xiaomi_miot/core/hass_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,19 @@ async def async_update(self):

def on_device_update(self, data: dict, only_info=False):
state_change = False
self._attr_available = self.device.available
available = self.device.available

if not only_info:
pass
elif isinstance(self.conv, InfoConv):
self._attr_available = True
self._attr_available = available = True
self._attr_icon = data.get('icon', self._attr_icon)
self._attr_extra_state_attributes.update(data)
self._attr_extra_state_attributes = data
else:
return

if keys := self.listen_attrs & data.keys():
self._attr_available = available
self.set_state(data)
state_change = True
for key in keys:
Expand Down

0 comments on commit cb8140e

Please sign in to comment.