mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2025-04-02 07:45:31 +08:00
misc: remove tev dependency for lan control & fixs (#333)
* 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
This commit is contained in:
parent
310029d8ed
commit
196e19d10a
@ -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."""
|
||||
|
@ -1089,7 +1089,7 @@ class MIoTClient:
|
||||
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={
|
||||
|
@ -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):
|
||||
@ -141,3 +142,7 @@ class MIoTConfigError(MIoTError):
|
||||
|
||||
class MIoTOptionsError(MIoTError):
|
||||
...
|
||||
|
||||
|
||||
class MIoTLanError(MIoTError):
|
||||
...
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -52,7 +52,7 @@ import socket
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, auto
|
||||
import subprocess
|
||||
from typing import Callable, Optional
|
||||
from typing import Callable, Coroutine, Optional
|
||||
import psutil
|
||||
import ipaddress
|
||||
|
||||
@ -97,7 +97,7 @@ class MIoTNetwork:
|
||||
|
||||
_sub_list_network_status: dict[str, Callable[[bool], asyncio.Future]]
|
||||
_sub_list_network_info: dict[str, Callable[[
|
||||
InterfaceStatus, NetworkInfo], asyncio.Future]]
|
||||
InterfaceStatus, NetworkInfo], Coroutine]]
|
||||
|
||||
_ping_address_priority: int
|
||||
|
||||
@ -155,7 +155,7 @@ class MIoTNetwork:
|
||||
|
||||
def sub_network_info(
|
||||
self, key: str,
|
||||
handler: Callable[[InterfaceStatus, NetworkInfo], asyncio.Future]
|
||||
handler: Callable[[InterfaceStatus, NetworkInfo], Coroutine]
|
||||
) -> None:
|
||||
self._sub_list_network_info[key] = handler
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user