mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 23:50:42 +08:00
style: format code
This commit is contained in:
parent
0668985969
commit
43fc8c4d56
@ -162,7 +162,6 @@ class _MipsRequest:
|
|||||||
timer: asyncio.TimerHandle | None
|
timer: asyncio.TimerHandle | None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class _MipsBroadcast:
|
class _MipsBroadcast:
|
||||||
"""MIoT Pub/Sub broadcast."""
|
"""MIoT Pub/Sub broadcast."""
|
||||||
@ -196,6 +195,7 @@ class MIoTDeviceState(Enum):
|
|||||||
OFFLINE = auto()
|
OFFLINE = auto()
|
||||||
ONLINE = auto()
|
ONLINE = auto()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MipsDeviceState:
|
class MipsDeviceState:
|
||||||
"""MIoT Pub/Sub device state."""
|
"""MIoT Pub/Sub device state."""
|
||||||
@ -208,6 +208,7 @@ class MipsDeviceState:
|
|||||||
handler: Callable[[str, MIoTDeviceState, Any], None] | None = None
|
handler: Callable[[str, MIoTDeviceState, Any], None] | None = None
|
||||||
handler_ctx: Any = None
|
handler_ctx: Any = None
|
||||||
|
|
||||||
|
|
||||||
class _MipsClient(ABC):
|
class _MipsClient(ABC):
|
||||||
"""MIoT Pub/Sub client."""
|
"""MIoT Pub/Sub client."""
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@ -292,7 +293,6 @@ class _MipsClient(ABC):
|
|||||||
self._mips_sub_pending_timer = None
|
self._mips_sub_pending_timer = None
|
||||||
# DO NOT start the thread yet. Do that on connect
|
# DO NOT start the thread yet. Do that on connect
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client_id(self) -> str:
|
def client_id(self) -> str:
|
||||||
return self._client_id
|
return self._client_id
|
||||||
@ -323,8 +323,8 @@ class _MipsClient(ABC):
|
|||||||
self._internal_loop = asyncio.new_event_loop()
|
self._internal_loop = asyncio.new_event_loop()
|
||||||
self._mips_thread = threading.Thread(target=self.__mips_loop_thread)
|
self._mips_thread = threading.Thread(target=self.__mips_loop_thread)
|
||||||
self._mips_thread.daemon = True
|
self._mips_thread.daemon = True
|
||||||
self._mips_thread.name = \
|
self._mips_thread.name = (
|
||||||
self._client_id if thread_name is None else thread_name
|
self._client_id if thread_name is None else thread_name)
|
||||||
self._mips_thread.start()
|
self._mips_thread.start()
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@ -476,13 +476,13 @@ class _MipsClient(ABC):
|
|||||||
) -> dict: ...
|
) -> dict: ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _on_mips_message(self, topic: str, payload: bytes) -> None:...
|
def _on_mips_message(self, topic: str, payload: bytes) -> None: ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _on_mips_connect(self, rc: int, props: dict) -> None:...
|
def _on_mips_connect(self, rc: int, props: dict) -> None: ...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _on_mips_disconnect(self, rc: int, props: dict) -> None:...
|
def _on_mips_disconnect(self, rc: int, props: dict) -> None: ...
|
||||||
|
|
||||||
@final
|
@final
|
||||||
def _mips_sub_internal(self, topic: str) -> None:
|
def _mips_sub_internal(self, topic: str) -> None:
|
||||||
@ -626,7 +626,7 @@ class _MipsClient(ABC):
|
|||||||
self._event_connect.set()
|
self._event_connect.set()
|
||||||
self._event_disconnect.clear()
|
self._event_disconnect.clear()
|
||||||
|
|
||||||
def __on_connect_failed(self, client:Client, user_data:Any) -> None:
|
def __on_connect_failed(self, client: Client, user_data: Any) -> None:
|
||||||
self.log_error('mips connect failed')
|
self.log_error('mips connect failed')
|
||||||
# Try to reconnect
|
# Try to reconnect
|
||||||
self.__mips_try_reconnect()
|
self.__mips_try_reconnect()
|
||||||
@ -1029,7 +1029,7 @@ class MipsCloudClient(_MipsClient):
|
|||||||
if not bc_list:
|
if not bc_list:
|
||||||
return
|
return
|
||||||
# The message from the cloud is not packed.
|
# The message from the cloud is not packed.
|
||||||
payload_str:str = payload.decode('utf-8')
|
payload_str: str = payload.decode('utf-8')
|
||||||
# self.log_debug(f"on broadcast, {topic}, {payload}")
|
# self.log_debug(f"on broadcast, {topic}, {payload}")
|
||||||
for item in bc_list or []:
|
for item in bc_list or []:
|
||||||
if item.handler is None:
|
if item.handler is None:
|
||||||
@ -1440,7 +1440,7 @@ class MipsLocalClient(_MipsClient):
|
|||||||
# Sub broadcast topic
|
# Sub broadcast topic
|
||||||
for topic, _ in list(self._msg_matcher.iter_all_nodes()):
|
for topic, _ in list(self._msg_matcher.iter_all_nodes()):
|
||||||
self._mips_sub_internal(
|
self._mips_sub_internal(
|
||||||
topic=re.sub(f'^{self._did}', 'master', topic))\
|
topic=re.sub(f'^{self._did}', 'master', topic))
|
||||||
|
|
||||||
@final
|
@final
|
||||||
def _on_mips_disconnect(self, rc: int, props: dict) -> None:
|
def _on_mips_disconnect(self, rc: int, props: dict) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user