Skip to content

Commit

Permalink
⌛ add option parallel_updates (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Jul 7, 2024
1 parent 4640304 commit 24a7527
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions custom_components/xiaomi_miot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,25 @@ def update_custom_scan_interval(self, only_custom=False):
self.platform.scan_interval = tim
_LOGGER.debug('%s: Update custom scan interval: %s', self.name_model, tim)

def update_custom_parallel_updates(self):
if not self.hass:
return False
if not hasattr(self, '_unique_did'):
return False
num = self.custom_config_integer('parallel_updates', 0)
if not num:
return False
did = self._unique_did
self.hass.data[DOMAIN].setdefault(did, {})
dcs = self.hass.data[DOMAIN].get(did, {})
pus = dcs.get('parallel_updates')
if not pus:
pus = asyncio.Semaphore(num)
self.hass.data[DOMAIN][did]['parallel_updates'] = pus
_LOGGER.warning('%s: Update custom parallel updates: %s', self.name_model, num)
self.parallel_updates = pus
return pus

def filter_state_attributes(self, dat: dict):
if exl := self.global_config('exclude_state_attributes'):
exl = cv.ensure_list(exl)
Expand Down Expand Up @@ -973,6 +992,7 @@ async def async_added_to_hass(self):
await super().async_added_to_hass()
if self.platform:
self.update_custom_scan_interval()
self.update_custom_parallel_updates()
if self.platform.config_entry:
eid = self.platform.config_entry.entry_id
self._add_entities = self.hass.data[DOMAIN][eid].get('add_entities') or {}
Expand Down
1 change: 1 addition & 0 deletions custom_components/xiaomi_miot/core/device_customizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
},
'cuco.plug.*': {
'main_miot_services': 'switch-2',
'parallel_updates': 3,
},
'cuco.plug.*:electric_current': {
'state_class': 'measurement',
Expand Down
1 change: 0 additions & 1 deletion custom_components/xiaomi_miot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

_LOGGER = logging.getLogger(__name__)
DATA_KEY = f'{ENTITY_DOMAIN}.{DOMAIN}'
PARALLEL_UPDATES = 3 # issue#1749

SERVICE_TO_METHOD = {}

Expand Down

0 comments on commit 24a7527

Please sign in to comment.