mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 23:50:42 +08:00
fix: fix mdns type error
This commit is contained in:
parent
4e3fcc9705
commit
8c0461e88c
@ -50,7 +50,7 @@ import base64
|
|||||||
import binascii
|
import binascii
|
||||||
import copy
|
import copy
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Coroutine, Optional
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from zeroconf import (
|
from zeroconf import (
|
||||||
@ -98,8 +98,8 @@ class MipsServiceData:
|
|||||||
def __init__(self, service_info: AsyncServiceInfo) -> None:
|
def __init__(self, service_info: AsyncServiceInfo) -> None:
|
||||||
if service_info is None:
|
if service_info is None:
|
||||||
raise MipsServiceError('invalid params')
|
raise MipsServiceError('invalid params')
|
||||||
properties = service_info.decoded_properties
|
properties: dict = service_info.decoded_properties
|
||||||
if properties is None:
|
if not properties:
|
||||||
raise MipsServiceError('invalid service properties')
|
raise MipsServiceError('invalid service properties')
|
||||||
self.profile = properties.get('profile', None)
|
self.profile = properties.get('profile', None)
|
||||||
if self.profile is None:
|
if self.profile is None:
|
||||||
@ -111,9 +111,11 @@ class MipsServiceData:
|
|||||||
if not self.addresses:
|
if not self.addresses:
|
||||||
raise MipsServiceError('invalid addresses')
|
raise MipsServiceError('invalid addresses')
|
||||||
self.addresses.sort()
|
self.addresses.sort()
|
||||||
|
if not service_info.port:
|
||||||
|
raise MipsServiceError('invalid port')
|
||||||
self.port = service_info.port
|
self.port = service_info.port
|
||||||
self.type = service_info.type
|
self.type = service_info.type
|
||||||
self.server = service_info.server
|
self.server = service_info.server or ''
|
||||||
# Parse profile
|
# Parse profile
|
||||||
self.did = str(int.from_bytes(self.profile_bin[1:9]))
|
self.did = str(int.from_bytes(self.profile_bin[1:9]))
|
||||||
self.group_id = binascii.hexlify(
|
self.group_id = binascii.hexlify(
|
||||||
@ -150,8 +152,8 @@ class MipsService:
|
|||||||
_aio_browser: AsyncServiceBrowser
|
_aio_browser: AsyncServiceBrowser
|
||||||
_services: dict[str, dict]
|
_services: dict[str, dict]
|
||||||
# key = (key, group_id)
|
# key = (key, group_id)
|
||||||
_sub_list: dict[(str, str), Callable[[
|
_sub_list: dict[tuple[str, str], Callable[[
|
||||||
str, MipsServiceState, dict], asyncio.Future]]
|
str, MipsServiceState, dict], Coroutine]]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, aiozc: AsyncZeroconf,
|
self, aiozc: AsyncZeroconf,
|
||||||
@ -159,7 +161,6 @@ class MipsService:
|
|||||||
) -> None:
|
) -> None:
|
||||||
self._aiozc = aiozc
|
self._aiozc = aiozc
|
||||||
self._main_loop = loop or asyncio.get_running_loop()
|
self._main_loop = loop or asyncio.get_running_loop()
|
||||||
self._aio_browser = None
|
|
||||||
|
|
||||||
self._services = {}
|
self._services = {}
|
||||||
self._sub_list = {}
|
self._sub_list = {}
|
||||||
@ -207,7 +208,7 @@ class MipsService:
|
|||||||
|
|
||||||
def sub_service_change(
|
def sub_service_change(
|
||||||
self, key: str, group_id: str,
|
self, key: str, group_id: str,
|
||||||
handler: Callable[[str, MipsServiceState, dict], asyncio.Future]
|
handler: Callable[[str, MipsServiceState, dict], Coroutine]
|
||||||
) -> None:
|
) -> None:
|
||||||
if key is None or group_id is None or handler is None:
|
if key is None or group_id is None or handler is None:
|
||||||
raise MipsServiceError('invalid params')
|
raise MipsServiceError('invalid params')
|
||||||
@ -232,7 +233,7 @@ class MipsService:
|
|||||||
for item in list(self._services.values()):
|
for item in list(self._services.values()):
|
||||||
if item['name'] != name:
|
if item['name'] != name:
|
||||||
continue
|
continue
|
||||||
service_data = self._services.pop(item['group_id'], None)
|
service_data = self._services.pop(item['group_id'], {})
|
||||||
self.__call_service_change(
|
self.__call_service_change(
|
||||||
state=MipsServiceState.REMOVED, data=service_data)
|
state=MipsServiceState.REMOVED, data=service_data)
|
||||||
return
|
return
|
||||||
@ -275,10 +276,10 @@ class MipsService:
|
|||||||
_LOGGER.error('invalid mips service, %s, %s', error, info)
|
_LOGGER.error('invalid mips service, %s, %s', error, info)
|
||||||
|
|
||||||
def __call_service_change(
|
def __call_service_change(
|
||||||
self, state: MipsServiceState, data: dict = None
|
self, state: MipsServiceState, data: dict
|
||||||
) -> None:
|
) -> None:
|
||||||
_LOGGER.info('call service change, %s, %s', state, data)
|
_LOGGER.info('call service change, %s, %s', state, data)
|
||||||
for keys in list(self._sub_list.keys()):
|
for keys in list(self._sub_list.keys()):
|
||||||
if keys[1] in [data['group_id'], '*']:
|
if keys[1] in [data.get('group_id', None), '*']:
|
||||||
self._main_loop.create_task(
|
self._main_loop.create_task(
|
||||||
self._sub_list[keys](data['group_id'], state, data))
|
self._sub_list[keys](data['group_id'], state, data))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user