mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2025-08-05 14:58:52 +08:00
fix: fix type error, wrong use of any and Any (#338)
* fix: fix type error, wrong use of any and Any * fix: wrong use of session close * fix: fix test_lan type error * fix: remove __del__ * feat: oauth, http add deinit_async
This commit is contained in:
@ -47,7 +47,7 @@ MIoT device instance.
|
||||
"""
|
||||
import asyncio
|
||||
from abc import abstractmethod
|
||||
from typing import Callable, Optional
|
||||
from typing import Any, Callable, Optional
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
@ -103,7 +103,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class MIoTEntityData:
|
||||
"""MIoT Entity Data."""
|
||||
platform: str
|
||||
device_class: any
|
||||
device_class: Any
|
||||
spec: MIoTSpecInstance | MIoTSpecService
|
||||
|
||||
props: set[MIoTSpecProperty]
|
||||
@ -243,8 +243,8 @@ class MIoTDevice:
|
||||
return True
|
||||
|
||||
def sub_property(
|
||||
self, handler: Callable[[dict, any], None], siid: int = None,
|
||||
piid: int = None, handler_ctx: any = None
|
||||
self, handler: Callable[[dict, Any], None], siid: int = None,
|
||||
piid: int = None, handler_ctx: Any = None
|
||||
) -> bool:
|
||||
return self.miot_client.sub_prop(
|
||||
did=self._did, handler=handler, siid=siid, piid=piid,
|
||||
@ -254,8 +254,8 @@ class MIoTDevice:
|
||||
return self.miot_client.unsub_prop(did=self._did, siid=siid, piid=piid)
|
||||
|
||||
def sub_event(
|
||||
self, handler: Callable[[dict, any], None], siid: int = None,
|
||||
eiid: int = None, handler_ctx: any = None
|
||||
self, handler: Callable[[dict, Any], None], siid: int = None,
|
||||
eiid: int = None, handler_ctx: Any = None
|
||||
) -> bool:
|
||||
return self.miot_client.sub_event(
|
||||
did=self._did, handler=handler, siid=siid, eiid=eiid,
|
||||
@ -688,7 +688,7 @@ class MIoTDevice:
|
||||
return None
|
||||
|
||||
def __on_device_state_changed(
|
||||
self, did: str, state: MIoTDeviceState, ctx: any
|
||||
self, did: str, state: MIoTDeviceState, ctx: Any
|
||||
) -> None:
|
||||
self._online = state
|
||||
for key, handler in self._device_state_sub_list.items():
|
||||
@ -704,11 +704,11 @@ class MIoTServiceEntity(Entity):
|
||||
entity_data: MIoTEntityData
|
||||
|
||||
_main_loop: asyncio.AbstractEventLoop
|
||||
_prop_value_map: dict[MIoTSpecProperty, any]
|
||||
_prop_value_map: dict[MIoTSpecProperty, Any]
|
||||
|
||||
_event_occurred_handler: Callable[[MIoTSpecEvent, dict], None]
|
||||
_prop_changed_subs: dict[
|
||||
MIoTSpecProperty, Callable[[MIoTSpecProperty, any], None]]
|
||||
MIoTSpecProperty, Callable[[MIoTSpecProperty, Any], None]]
|
||||
|
||||
_pending_write_ha_state_timer: Optional[asyncio.TimerHandle]
|
||||
|
||||
@ -759,7 +759,7 @@ class MIoTServiceEntity(Entity):
|
||||
|
||||
def sub_prop_changed(
|
||||
self, prop: MIoTSpecProperty,
|
||||
handler: Callable[[MIoTSpecProperty, any], None]
|
||||
handler: Callable[[MIoTSpecProperty, Any], None]
|
||||
) -> None:
|
||||
if not prop or not handler:
|
||||
_LOGGER.error(
|
||||
@ -816,13 +816,13 @@ class MIoTServiceEntity(Entity):
|
||||
self.miot_device.unsub_event(
|
||||
siid=event.service.iid, eiid=event.iid)
|
||||
|
||||
def get_map_description(self, map_: dict[int, any], key: int) -> any:
|
||||
def get_map_description(self, map_: dict[int, Any], key: int) -> Any:
|
||||
if map_ is None:
|
||||
return None
|
||||
return map_.get(key, None)
|
||||
|
||||
def get_map_value(
|
||||
self, map_: dict[int, any], description: any
|
||||
self, map_: dict[int, Any], description: Any
|
||||
) -> Optional[int]:
|
||||
if map_ is None:
|
||||
return None
|
||||
@ -831,7 +831,7 @@ class MIoTServiceEntity(Entity):
|
||||
return key
|
||||
return None
|
||||
|
||||
def get_prop_value(self, prop: MIoTSpecProperty) -> any:
|
||||
def get_prop_value(self, prop: MIoTSpecProperty) -> Any:
|
||||
if not prop:
|
||||
_LOGGER.error(
|
||||
'get_prop_value error, property is None, %s, %s',
|
||||
@ -839,7 +839,7 @@ class MIoTServiceEntity(Entity):
|
||||
return None
|
||||
return self._prop_value_map.get(prop, None)
|
||||
|
||||
def set_prop_value(self, prop: MIoTSpecProperty, value: any) -> None:
|
||||
def set_prop_value(self, prop: MIoTSpecProperty, value: Any) -> None:
|
||||
if not prop:
|
||||
_LOGGER.error(
|
||||
'set_prop_value error, property is None, %s, %s',
|
||||
@ -848,7 +848,7 @@ class MIoTServiceEntity(Entity):
|
||||
self._prop_value_map[prop] = value
|
||||
|
||||
async def set_property_async(
|
||||
self, prop: MIoTSpecProperty, value: any, update: bool = True
|
||||
self, prop: MIoTSpecProperty, value: Any, update: bool = True
|
||||
) -> bool:
|
||||
value = prop.value_format(value)
|
||||
if not prop:
|
||||
@ -875,7 +875,7 @@ class MIoTServiceEntity(Entity):
|
||||
self.async_write_ha_state()
|
||||
return True
|
||||
|
||||
async def get_property_async(self, prop: MIoTSpecProperty) -> any:
|
||||
async def get_property_async(self, prop: MIoTSpecProperty) -> Any:
|
||||
if not prop:
|
||||
_LOGGER.error(
|
||||
'get property failed, property is None, %s, %s',
|
||||
@ -914,7 +914,7 @@ class MIoTServiceEntity(Entity):
|
||||
f'{e}, {self.entity_id}, {self.name}, {action.name}') from e
|
||||
return True
|
||||
|
||||
def __on_properties_changed(self, params: dict, ctx: any) -> None:
|
||||
def __on_properties_changed(self, params: dict, ctx: Any) -> None:
|
||||
_LOGGER.debug('properties changed, %s', params)
|
||||
for prop in self.entity_data.props:
|
||||
if (
|
||||
@ -922,7 +922,7 @@ class MIoTServiceEntity(Entity):
|
||||
or prop.service.iid != params['siid']
|
||||
):
|
||||
continue
|
||||
value: any = prop.value_format(params['value'])
|
||||
value: Any = prop.value_format(params['value'])
|
||||
self._prop_value_map[prop] = value
|
||||
if prop in self._prop_changed_subs:
|
||||
self._prop_changed_subs[prop](prop, value)
|
||||
@ -930,7 +930,7 @@ class MIoTServiceEntity(Entity):
|
||||
if not self._pending_write_ha_state_timer:
|
||||
self.async_write_ha_state()
|
||||
|
||||
def __on_event_occurred(self, params: dict, ctx: any) -> None:
|
||||
def __on_event_occurred(self, params: dict, ctx: Any) -> None:
|
||||
_LOGGER.debug('event occurred, %s', params)
|
||||
if self._event_occurred_handler is None:
|
||||
return
|
||||
@ -988,9 +988,9 @@ class MIoTPropertyEntity(Entity):
|
||||
_main_loop: asyncio.AbstractEventLoop
|
||||
# {'min':int, 'max':int, 'step': int}
|
||||
_value_range: dict[str, int]
|
||||
# {any: any}
|
||||
_value_list: dict[any, any]
|
||||
_value: any
|
||||
# {Any: Any}
|
||||
_value_list: dict[Any, Any]
|
||||
_value: Any
|
||||
|
||||
_pending_write_ha_state_timer: Optional[asyncio.TimerHandle]
|
||||
|
||||
@ -1054,12 +1054,12 @@ class MIoTPropertyEntity(Entity):
|
||||
self.miot_device.unsub_property(
|
||||
siid=self.service.iid, piid=self.spec.iid)
|
||||
|
||||
def get_vlist_description(self, value: any) -> str:
|
||||
def get_vlist_description(self, value: Any) -> str:
|
||||
if not self._value_list:
|
||||
return None
|
||||
return self._value_list.get(value, None)
|
||||
|
||||
def get_vlist_value(self, description: str) -> any:
|
||||
def get_vlist_value(self, description: str) -> Any:
|
||||
if not self._value_list:
|
||||
return None
|
||||
for key, value in self._value_list.items():
|
||||
@ -1067,7 +1067,7 @@ class MIoTPropertyEntity(Entity):
|
||||
return key
|
||||
return None
|
||||
|
||||
async def set_property_async(self, value: any) -> bool:
|
||||
async def set_property_async(self, value: Any) -> bool:
|
||||
if not self.spec.writable:
|
||||
raise RuntimeError(
|
||||
f'set property failed, not writable, '
|
||||
@ -1084,7 +1084,7 @@ class MIoTPropertyEntity(Entity):
|
||||
self.async_write_ha_state()
|
||||
return True
|
||||
|
||||
async def get_property_async(self) -> any:
|
||||
async def get_property_async(self) -> Any:
|
||||
if not self.spec.readable:
|
||||
_LOGGER.error(
|
||||
'get property failed, not readable, %s, %s',
|
||||
@ -1095,7 +1095,7 @@ class MIoTPropertyEntity(Entity):
|
||||
did=self.miot_device.did, siid=self.spec.service.iid,
|
||||
piid=self.spec.iid))
|
||||
|
||||
def __on_value_changed(self, params: dict, ctx: any) -> None:
|
||||
def __on_value_changed(self, params: dict, ctx: Any) -> None:
|
||||
_LOGGER.debug('property changed, %s', params)
|
||||
self._value = self.spec.value_format(params['value'])
|
||||
if not self._pending_write_ha_state_timer:
|
||||
@ -1135,7 +1135,7 @@ class MIoTEventEntity(Entity):
|
||||
service: MIoTSpecService
|
||||
|
||||
_main_loop: asyncio.AbstractEventLoop
|
||||
_value: any
|
||||
_value: Any
|
||||
_attr_event_types: list[str]
|
||||
_arguments_map: dict[int, str]
|
||||
|
||||
@ -1192,10 +1192,10 @@ class MIoTEventEntity(Entity):
|
||||
|
||||
@abstractmethod
|
||||
def on_event_occurred(
|
||||
self, name: str, arguments: list[dict[int, any]]
|
||||
self, name: str, arguments: list[dict[int, Any]]
|
||||
): ...
|
||||
|
||||
def __on_event_occurred(self, params: dict, ctx: any) -> None:
|
||||
def __on_event_occurred(self, params: dict, ctx: Any) -> None:
|
||||
_LOGGER.debug('event occurred, %s', params)
|
||||
trans_arg = {}
|
||||
try:
|
||||
|
Reference in New Issue
Block a user