Skip to content

Commit

Permalink
misc: remove tev dependency for lan control & fixs (#333)
Browse files Browse the repository at this point in the history
* Remove tev & fix some type issues

* Use call_soon_threadsafe instead of event fd for ipc

* fix lint

* add tev back

* fix lint

* ignore broad exception warning

* revert changes in the license

* do not set asyncio event loop

* fix racing condition

* remove unused data classes

* change internal class scope

* set timers to None after cancel

* Adjust import order

* fix typo

* Fix typo in comments

* guard lan apis with init_done
  • Loading branch information
chemwolf6922 authored Dec 30, 2024
1 parent 310029d commit 196e19d
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 476 deletions.
3 changes: 3 additions & 0 deletions custom_components/xiaomi_home/miot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def randomize_int(value: int, ratio: float) -> int:
"""Randomize an integer value."""
return int(value * (1 - ratio + random.random()*2*ratio))

def randomize_float(value: float, ratio: float) -> float:
"""Randomize a float value."""
return value * (1 - ratio + random.random()*2*ratio)

class MIoTMatcher(MQTTMatcher):
"""MIoT Pub/Sub topic matcher."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/miot/miot_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ async def __on_miot_lan_state_change(self, state: bool) -> None:
handler=self.__on_lan_device_state_changed)
for did, info in (
await self._miot_lan.get_dev_list_async()).items():
self.__on_lan_device_state_changed(
await self.__on_lan_device_state_changed(
did=did, state=info, ctx=None)
_LOGGER.info('lan device list, %s', self._device_list_lan)
self._miot_lan.update_devices(devices={
Expand Down
5 changes: 5 additions & 0 deletions custom_components/xiaomi_home/miot/miot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MIoTErrorCode(Enum):
# Config flow error code, -10100
# Options flow error code , -10110
# MIoT lan error code, -10120
CODE_LAN_UNAVAILABLE = -10120


class MIoTError(Exception):
Expand Down Expand Up @@ -141,3 +142,7 @@ class MIoTConfigError(MIoTError):

class MIoTOptionsError(MIoTError):
...


class MIoTLanError(MIoTError):
...
Loading

0 comments on commit 196e19d

Please sign in to comment.