feat: support devices filter & devices changed notify (#332)

* feat: add devices filter page

* doc: update translations and i18n

* fix: cancel miot http timer

* feat: improve devices filter

* doc: update translations/de

* fix: i18n type error

* feat: config flow support device filter

* fix: fix mdns type error

* fix: fix miot client i18n logic

* feat: add connect type

* doc: update translations and i18n

* feat: update auth info save logic

* feat: improve config flow devices filter

* fix: fix some type error

* doc: update translations for option flow

* fix: fix option flow type error

* feat: support option flow devices filter

* doc: update option flow tranlations

* feat: update webhook handle func to private

* feat: update config flow translations

* doc: update tranlations text

* feat: custom display device changed notify

* feat: device changed notify logical refinement

* doc: update translations content
This commit is contained in:
Paul Shawn
2024-12-24 21:28:50 +08:00
committed by GitHub
parent 78461cbd8a
commit 29b7489ac7
27 changed files with 1734 additions and 387 deletions

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "Geräte",
"found_central_gateway": ", lokales zentrales Gateway gefunden"
"found_central_gateway": ", lokales zentrales Gateway gefunden",
"without_room": "Kein Raum zugewiesen",
"no_display": "nicht anzeigen"
},
"control_mode": {
"auto": "automatisch",
"cloud": "Cloud"
},
"statistics_logic": {
"or": "ODER-Logik",
"and": "UND-Logik"
},
"filter_mode": {
"exclude": "ausschließen",
"include": "einschließen"
},
"connect_type": {
"0": "WiFi",
"1": "yunyi-Gerät",
"2": "Cloud-Gerät",
"3": "ZigBee",
"4": "webSocket",
"5": "virtuelles Gerät",
"6": "BLE",
"7": "lokaler AP",
"8": "WiFi+BLE",
"9": "andere",
"10": "Funktions-Plug-in",
"11": "Zellnetz",
"12": "Kabel",
"13": "NB-IoT",
"14": "Drittanbieter-Cloud-Zugriff",
"15": "Infrarot-Fernbedienungsgerät",
"16": "BLE-Mesh",
"17": "virtuelle Gerätegruppe",
"18": "Gateway-Untergerät",
"19": "Sicherheitsstufe Gateway-Untergerät",
"22": "PLC",
"23": "nur Kabel",
"24": "Matter",
"25": "WiFi+Zellnetz"
},
"room_name_rule": {
"none": "nicht synchronisieren",
"home_room": "Hausname und Raumname (Xiaomi Home Schlafzimmer)",
@ -18,6 +54,11 @@
"enable": "aktivieren",
"disable": "deaktivieren"
},
"device_state": {
"add": "hinzufügen",
"del": "nicht verfügbar",
"offline": "offline"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Hinweis]** Es wurden mehrere Netzwerkkarten erkannt, die möglicherweise mit demselben Netzwerk verbunden sind. Bitte achten Sie auf die Auswahl.",
"net_unavailable": "Schnittstelle nicht verfügbar"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "Devices",
"found_central_gateway": ", Found Local Central Hub Gateway"
"found_central_gateway": ", Found Local Central Hub Gateway",
"without_room": "No room assigned",
"no_display": "Do not display"
},
"control_mode": {
"auto": "Auto",
"cloud": "Cloud"
},
"statistics_logic": {
"or": "OR logic",
"and": "AND logic"
},
"filter_mode": {
"exclude": "Exclude",
"include": "Include"
},
"connect_type": {
"0": "WiFi",
"1": "yunyi device",
"2": "Cloud device",
"3": "ZigBee",
"4": "webSocket",
"5": "Virtual device",
"6": "BLE",
"7": "Local AP",
"8": "WiFi+BLE",
"9": "Other",
"10": "Function plug-in",
"11": "Cellular network",
"12": "Cable",
"13": "NB-IoT",
"14": "Third-party cloud access",
"15": "Infrared remote control device",
"16": "BLE-Mesh",
"17": "Virtual device group",
"18": "Gateway sub-device",
"19": "Security level gateway sub-device",
"22": "PLC",
"23": "Cable only",
"24": "Matter",
"25": "WiFi+Cellular network"
},
"room_name_rule": {
"none": "Do not synchronize",
"home_room": "Home Name and Room Name (Xiaomi Home Bedroom)",
@ -18,6 +54,11 @@
"enable": "Enable",
"disable": "Disable"
},
"device_state": {
"add": "Add",
"del": "Unavailable",
"offline": "Offline"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Notice]** Multiple network cards detected that may be connected to the same network. Please pay attention to the selection.",
"net_unavailable": "Interface unavailable"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "dispositivos",
"found_central_gateway": ", se encontró la puerta de enlace central local"
"found_central_gateway": ", se encontró la puerta de enlace central local",
"without_room": "Sin habitación asignada",
"no_display": "no mostrar"
},
"control_mode": {
"auto": "automático",
"cloud": "nube"
},
"statistics_logic": {
"or": "lógica OR",
"and": "lógica AND"
},
"filter_mode": {
"exclude": "excluir",
"include": "incluir"
},
"connect_type": {
"0": "WiFi",
"1": "dispositivo yunyi",
"2": "dispositivo de nube",
"3": "ZigBee",
"4": "webSocket",
"5": "dispositivo virtual",
"6": "BLE",
"7": "AP local",
"8": "WiFi+BLE",
"9": "otro",
"10": "complemento de función",
"11": "red celular",
"12": "cable",
"13": "NB-IoT",
"14": "acceso a la nube de terceros",
"15": "dispositivo de control remoto infrarrojo",
"16": "BLE-Mesh",
"17": "grupo de dispositivos virtuales",
"18": "subdispositivo de puerta de enlace",
"19": "subdispositivo de puerta de enlace de nivel de seguridad",
"22": "PLC",
"23": "solo cable",
"24": "Matter",
"25": "WiFi+red celular"
},
"room_name_rule": {
"none": "no sincronizar",
"home_room": "nombre de la casa y nombre de la habitación (Xiaomi Home Dormitorio)",
@ -18,6 +54,11 @@
"enable": "habilitar",
"disable": "deshabilitar"
},
"device_state": {
"add": "agregar",
"del": "no disponible",
"offline": "fuera de línea"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Aviso]** Se detectaron varias tarjetas de red que pueden estar conectadas a la misma red. Por favor, preste atención a la selección.",
"net_unavailable": "Interfaz no disponible"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "appareils",
"found_central_gateway": ", passerelle centrale locale trouvée"
"found_central_gateway": ", passerelle centrale locale trouvée",
"without_room": "Aucune pièce attribuée",
"no_display": "ne pas afficher"
},
"control_mode": {
"auto": "automatique",
"cloud": "cloud"
},
"statistics_logic": {
"or": "ou logique",
"and": "et logique"
},
"filter_mode": {
"exclude": "exclure",
"include": "inclure"
},
"connect_type": {
"0": "WiFi",
"1": "appareil yunyi",
"2": "appareil cloud",
"3": "ZigBee",
"4": "webSocket",
"5": "appareil virtuel",
"6": "BLE",
"7": "AP local",
"8": "WiFi+BLE",
"9": "autre",
"10": "plug-in de fonction",
"11": "réseau cellulaire",
"12": "câble",
"13": "NB-IoT",
"14": "accès cloud tiers",
"15": "appareil de télécommande infrarouge",
"16": "BLE-Mesh",
"17": "groupe d'appareils virtuels",
"18": "sous-appareil de passerelle",
"19": "niveau de sécurité sous-appareil de passerelle",
"22": "PLC",
"23": "câble uniquement",
"24": "Matter",
"25": "WiFi+réseau cellulaire"
},
"room_name_rule": {
"none": "ne pas synchroniser",
"home_room": "nom de la maison et nom de la pièce (Xiaomi Home Chambre)",
@ -18,6 +54,11 @@
"enable": "activer",
"disable": "désactiver"
},
"device_state": {
"add": "Ajouter",
"del": "Supprimer",
"offline": "hors ligne"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Remarque]** Plusieurs cartes réseau détectées qui peuvent être connectées au même réseau. Veuillez faire attention à la sélection.",
"net_unavailable": "Interface non disponible"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "デバイス",
"found_central_gateway": "、ローカル中央ゲートウェイが見つかりました"
"found_central_gateway": "、ローカル中央ゲートウェイが見つかりました",
"without_room": "部屋が割り当てられていません",
"no_display": "表示しない"
},
"control_mode": {
"auto": "自動",
"cloud": "クラウド"
},
"statistics_logic": {
"or": "ORロジック",
"and": "ANDロジック"
},
"filter_mode": {
"exclude": "除外",
"include": "含む"
},
"connect_type": {
"0": "WiFi",
"1": "yunyiデバイス",
"2": "クラウドデバイス",
"3": "ZigBee",
"4": "webSocket",
"5": "仮想デバイス",
"6": "BLE",
"7": "ローカルAP",
"8": "WiFi+BLE",
"9": "その他",
"10": "機能プラグイン",
"11": "セルラーネットワーク",
"12": "ケーブル",
"13": "NB-IoT",
"14": "サードパーティクラウドアクセス",
"15": "赤外線リモコンデバイス",
"16": "BLE-Mesh",
"17": "仮想デバイスグループ",
"18": "ゲートウェイサブデバイス",
"19": "セキュリティレベルゲートウェイサブデバイス",
"22": "PLC",
"23": "ケーブルのみ",
"24": "Matter",
"25": "WiFi+セルラーネットワーク"
},
"room_name_rule": {
"none": "同期しない",
"home_room": "家の名前と部屋の名前 Xiaomi Home 寝室)",
@ -18,6 +54,11 @@
"enable": "有効",
"disable": "無効"
},
"device_state": {
"add": "追加",
"del": "利用不可",
"offline": "オフライン"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[注意]** 複数のネットワークカードが同じネットワークに接続されている可能性があります。選択に注意してください。",
"net_unavailable": "インターフェースが利用できません"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "Apparaten",
"found_central_gateway": ", Lokale centrale hub-gateway gevonden"
"found_central_gateway": ", Lokale centrale hub-gateway gevonden",
"without_room": "Niet toegewezen kamer",
"no_display": "Niet weergeven"
},
"control_mode": {
"auto": "Automatisch",
"cloud": "Cloud"
},
"statistics_logic": {
"or": "OF-logica",
"and": "EN-logica"
},
"filter_mode": {
"exclude": "Uitsluiten",
"include": "Inclusief"
},
"connect_type": {
"0": "WiFi",
"1": "yunyi-apparaat",
"2": "Cloudapparaat",
"3": "ZigBee",
"4": "webSocket",
"5": "Virtueel apparaat",
"6": "BLE",
"7": "Lokaal AP",
"8": "WiFi+BLE",
"9": "Andere",
"10": "Functieplug-in",
"11": "Cellulair netwerk",
"12": "Kabel",
"13": "NB-IoT",
"14": "Toegang van derden tot de cloud",
"15": "Infrarood afstandsbedieningsapparaat",
"16": "BLE-Mesh",
"17": "Virtuele apparaatgroep",
"18": "Gateway sub-apparaat",
"19": "Beveiligingsniveau gateway sub-apparaat",
"22": "PLC",
"23": "Alleen kabel",
"24": "Matter",
"25": "WiFi+Cellulair netwerk"
},
"room_name_rule": {
"none": "Niet synchroniseren",
"home_room": "Huisnaam en Kamernaam (Xiaomi Home Slaapkamer)",
@ -18,6 +54,11 @@
"enable": "Inschakelen",
"disable": "Uitschakelen"
},
"device_state": {
"add": "Toevoegen",
"del": "Niet beschikbaar",
"offline": "Offline"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Let op]** Meerdere netwerkkaarten gedetecteerd die mogelijk zijn verbonden met hetzelfde netwerk. Let op bij de selectie.",
"net_unavailable": "Interface niet beschikbaar"
@ -92,4 +133,4 @@
"-706014006": "Apparaatbeschrijving niet gevonden"
}
}
}
}

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "dispositivos",
"found_central_gateway": "encontrado o gateway central local"
"found_central_gateway": "encontrado o gateway central local",
"without_room": "sem quarto atribuído",
"no_display": "não exibir"
},
"control_mode": {
"auto": "automático",
"cloud": "nuvem"
},
"statistics_logic": {
"or": "lógica OU",
"and": "lógica E"
},
"filter_mode": {
"exclude": "excluir",
"include": "incluir"
},
"connect_type": {
"0": "WiFi",
"1": "dispositivo yunyi",
"2": "dispositivo de nuvem",
"3": "ZigBee",
"4": "webSocket",
"5": "dispositivo virtual",
"6": "BLE",
"7": "AP local",
"8": "WiFi+BLE",
"9": "outro",
"10": "plug-in de função",
"11": "rede celular",
"12": "cabo",
"13": "NB-IoT",
"14": "acesso à nuvem de terceiros",
"15": "dispositivo de controle remoto infravermelho",
"16": "BLE-Mesh",
"17": "grupo de dispositivos virtuais",
"18": "subdispositivo de gateway",
"19": "subdispositivo de gateway de nível de segurança",
"22": "PLC",
"23": "somente cabo",
"24": "Matter",
"25": "WiFi+rede celular"
},
"room_name_rule": {
"none": "não sincronizado",
"home_room": "Nome da casa e nome do quarto (Xiaomi Home Quarto)",
@ -18,6 +54,11 @@
"enable": "habilitado",
"disable": "desabilitado"
},
"device_state": {
"add": "adicionar",
"del": "indisponível",
"offline": "offline"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Aviso]** Detectado múltiplas interfaces de rede que podem estar conectando à mesma rede, por favor, selecione a correta.",
"net_unavailable": "Interface indisponível"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "dispositivos",
"found_central_gateway": ", encontrou a central de gateway local"
"found_central_gateway": ", encontrou a central de gateway local",
"without_room": "Sem quarto atribuído",
"no_display": "Não exibir"
},
"control_mode": {
"auto": "Automático",
"cloud": "Nuvem"
},
"statistics_logic": {
"or": "Ou lógica",
"and": "E lógica"
},
"filter_mode": {
"exclude": "Excluir",
"include": "Incluir"
},
"connect_type": {
"0": "WiFi",
"1": "dispositivo yunyi",
"2": "dispositivo de nuvem",
"3": "ZigBee",
"4": "webSocket",
"5": "dispositivo virtual",
"6": "BLE",
"7": "AP local",
"8": "WiFi+BLE",
"9": "outro",
"10": "plug-in de função",
"11": "rede celular",
"12": "cabo",
"13": "NB-IoT",
"14": "acesso à nuvem de terceiros",
"15": "dispositivo de controle remoto infravermelho",
"16": "BLE-Mesh",
"17": "grupo de dispositivos virtuais",
"18": "subdispositivo de gateway",
"19": "subdispositivo de gateway de nível de segurança",
"22": "PLC",
"23": "somente cabo",
"24": "Matter",
"25": "WiFi+rede celular"
},
"room_name_rule": {
"none": "Não sincronizar",
"home_room": "Nome da casa e Nome do quarto (Xiaomi Home Quarto)",
@ -18,6 +54,11 @@
"enable": "Habilitar",
"disable": "Desabilitar"
},
"device_state": {
"add": "Adicionar",
"del": "Indisponível",
"offline": "Offline"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Aviso]** Detectado que várias interfaces podem estar conectadas à mesma rede, escolha com cuidado.",
"net_unavailable": "Interface indisponível"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "устройства",
"found_central_gateway": ", найден локальный центральный шлюз"
"found_central_gateway": ", найден локальный центральный шлюз",
"without_room": "без комнаты",
"no_display": "не отображать"
},
"control_mode": {
"auto": "автоматический",
"cloud": "облако"
},
"statistics_logic": {
"or": "логика ИЛИ",
"and": "логика И"
},
"filter_mode": {
"exclude": "исключить",
"include": "включить"
},
"connect_type": {
"0": "WiFi",
"1": "yunyi устройство",
"2": "Облачное устройство",
"3": "ZigBee",
"4": "webSocket",
"5": "Виртуальное устройство",
"6": "BLE",
"7": "Локальный AP",
"8": "WiFi+BLE",
"9": "Другое",
"10": "Плагин функции",
"11": "Сотовая сеть",
"12": "Кабель",
"13": "NB-IoT",
"14": "Доступ к стороннему облаку",
"15": "Устройство с ИК-пультом дистанционного управления",
"16": "BLE-Mesh",
"17": "Группа виртуальных устройств",
"18": "Подустройство шлюза",
"19": "Подустройство шлюза уровня безопасности",
"22": "PLC",
"23": "Только кабель",
"24": "Matter",
"25": "WiFi+Сотовая сеть"
},
"room_name_rule": {
"none": "не синхронизировать",
"home_room": "название дома и название комнаты (Xiaomi Home Спальня)",
@ -18,6 +54,11 @@
"enable": "Включить",
"disable": "Отключить"
},
"device_state": {
"add": "Добавить",
"del": "Недоступно",
"offline": "Не в сети"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[Уведомление]** Обнаружено несколько сетевых карт, которые могут быть подключены к одной и той же сети. Пожалуйста, обратите внимание на выбор.",
"net_unavailable": "Интерфейс недоступен"

View File

@ -2,7 +2,9 @@
"config": {
"other": {
"devices": "个设备",
"found_central_gateway": ",发现本地中枢网关"
"found_central_gateway": ",发现本地中枢网关",
"without_room": "未分配房间",
"no_display": "不显示"
},
"control_mode": {
"auto": "自动",
@ -14,10 +16,49 @@
"room": "房间名 (卧室)",
"home": "家庭名 (米家)"
},
"statistics_logic": {
"or": "或逻辑",
"and": "与逻辑"
},
"filter_mode": {
"exclude": "排除",
"include": "包含"
},
"connect_type": {
"0": "WiFi",
"1": "yunyi设备",
"2": "云接入设备",
"3": "ZigBee",
"4": "webSocket",
"5": "虚拟设备",
"6": "BLE",
"7": "本地AP",
"8": "WiFi+BLE",
"9": "其他",
"10": "功能插件",
"11": "蜂窝网",
"12": "网线",
"13": "NB-IoT",
"14": "第三方云接入",
"15": "红外遥控器子设备",
"16": "BLE-Mesh",
"17": "虚拟设备组",
"18": "代理网关子设备",
"19": "安全级代理网关子设备",
"22": "PLC",
"23": "仅网线",
"24": "Matter",
"25": "WiFi+蜂窝网"
},
"option_status": {
"enable": "启用",
"disable": "禁用"
},
"device_state": {
"add": "新增",
"del": "不可用",
"offline": "离线"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[提示]** 检测到多个网卡可能连接同一个网络,请注意选择。",
"net_unavailable": "接口不可用"

View File

@ -2,12 +2,48 @@
"config": {
"other": {
"devices": "個設備",
"found_central_gateway": ",發現本地中樞網關"
"found_central_gateway": ",發現本地中樞網關",
"without_room": "未分配房間",
"no_display": "不顯示"
},
"control_mode": {
"auto": "自動",
"cloud": "雲端"
},
"statistics_logic": {
"or": "或邏輯",
"and": "與邏輯"
},
"filter_mode": {
"exclude": "排除",
"include": "包含"
},
"connect_type": {
"0": "WiFi",
"1": "yunyi設備",
"2": "雲接入設備",
"3": "ZigBee",
"4": "webSocket",
"5": "虛擬設備",
"6": "BLE",
"7": "本地AP",
"8": "WiFi+BLE",
"9": "其他",
"10": "功能插件",
"11": "蜂窩網",
"12": "網線",
"13": "NB-IoT",
"14": "第三方雲接入",
"15": "紅外遙控器子設備",
"16": "BLE-Mesh",
"17": "虛擬設備組",
"18": "代理網關子設備",
"19": "安全級代理網關子設備",
"22": "PLC",
"23": "僅網線",
"24": "Matter",
"25": "WiFi+蜂窩網"
},
"room_name_rule": {
"none": "不同步",
"home_room": "家庭名 和 房間名 (米家 臥室)",
@ -18,6 +54,11 @@
"enable": "啟用",
"disable": "禁用"
},
"device_state": {
"add": "新增",
"del": "不可用",
"offline": "離線"
},
"lan_ctrl_config": {
"notice_net_dup": "\r\n**[提示]** 檢測到多個網卡可能連接同一個網絡,請注意選擇。",
"net_unavailable": "接口不可用"

View File

@ -164,9 +164,11 @@ class MIoTClient:
_refresh_props_retry_count: int
# Persistence notify handler, params: notify_id, title, message
_persistence_notify: Callable[[str, str, str], None]
_persistence_notify: Callable[[str, Optional[str], Optional[str]], None]
# Device list changed notify
_show_devices_changed_notify_timer: Optional[asyncio.TimerHandle]
# Display devices changed notify
_display_devs_notify: list[str]
def __init__(
self,
@ -231,6 +233,9 @@ class MIoTClient:
self._persistence_notify = None
self._show_devices_changed_notify_timer = None
self._display_devs_notify = entry_data.get(
'display_devices_changed_notify', ['add', 'del', 'offline'])
async def init_async(self) -> None:
# Load user config and check
self._user_config = await self._storage.load_user_config_async(
@ -239,14 +244,14 @@ class MIoTClient:
# Integration need to be add again
raise MIoTClientError('load_user_config_async error')
_LOGGER.debug('user config, %s', json.dumps(self._user_config))
# Load cache device list
await self.__load_cache_device_async()
# MIoT i18n client
self._i18n = MIoTI18n(
lang=self._entry_data.get(
'integration_language', DEFAULT_INTEGRATION_LANGUAGE),
loop=self._main_loop)
await self._i18n.init_async()
# Load cache device list
await self.__load_cache_device_async()
# MIoT oauth client instance
self._oauth = MIoTOauthClient(
client_id=OAUTH2_CLIENT_ID,
@ -459,6 +464,21 @@ class MIoTClient:
return self._entry_data.get(
'hide_non_standard_entities', False)
@property
def display_devices_changed_notify(self) -> list[str]:
return self._display_devs_notify
@display_devices_changed_notify.setter
def display_devices_changed_notify(self, value: list[str]) -> None:
if set(value) == set(self._display_devs_notify):
return
self._display_devs_notify = value
if value:
self.__request_show_devices_changed_notify()
else:
self._persistence_notify(
self.__gen_notify_key('dev_list_changed'), None, None)
@property
def device_list(self) -> dict:
return self._device_list_cache
@ -1716,15 +1736,16 @@ class MIoTClient:
count_offline: int = 0
# New devices
for did, info in {
**self._device_list_gateway, **self._device_list_cloud
}.items():
if did in self._device_list_cache:
continue
count_add += 1
message_add += (
f'- {info.get("name", "unknown")} ({did}, '
f'{info.get("model", "unknown")})\n')
if 'add' in self._display_devs_notify:
for did, info in {
**self._device_list_gateway, **self._device_list_cloud
}.items():
if did in self._device_list_cache:
continue
count_add += 1
message_add += (
f'- {info.get("name", "unknown")} ({did}, '
f'{info.get("model", "unknown")})\n')
# Get unavailable and offline devices
home_name_del: Optional[str] = None
home_name_offline: Optional[str] = None
@ -1734,7 +1755,7 @@ class MIoTClient:
if online:
# Skip online device
continue
if online is None:
if 'del' in self._display_devs_notify and online is None:
# Device not exist
if home_name_del != home_name_new:
message_del += f'\n[{home_name_new}]\n'
@ -1743,7 +1764,8 @@ class MIoTClient:
message_del += (
f'- {info.get("name", "unknown")} ({did}, '
f'{info.get("room_name", "unknown")})\n')
else:
continue
if 'offline' in self._display_devs_notify:
# Device offline
if home_name_offline != home_name_new:
message_offline += f'\n[{home_name_new}]\n'
@ -1754,19 +1776,19 @@ class MIoTClient:
f'{info.get("room_name", "unknown")})\n')
message = ''
if count_add:
if 'add' in self._display_devs_notify and count_add:
message += self._i18n.translate(
key='miot.client.device_list_add',
replace={
'count': count_add,
'message': message_add})
if count_del:
if 'del' in self._display_devs_notify and count_del:
message += self._i18n.translate(
key='miot.client.device_list_del',
replace={
'count': count_del,
'message': message_del})
if count_offline:
if 'offline' in self._display_devs_notify and count_offline:
message += self._i18n.translate(
key='miot.client.device_list_offline',
replace={
@ -1801,6 +1823,8 @@ class MIoTClient:
def __request_show_devices_changed_notify(
self, delay_sec: float = 6
) -> None:
if not self._display_devs_notify:
return
if not self._mips_cloud and not self._mips_local and not self._miot_lan:
return
if self._show_devices_changed_notify_timer:

View File

@ -254,6 +254,13 @@ class MIoTHttpClient:
self._session = aiohttp.ClientSession(loop=self._main_loop)
async def deinit_async(self) -> None:
if self._get_prop_timer:
self._get_prop_timer.cancel()
self._get_prop_timer = None
for item in self._get_prop_list.values():
fut: asyncio.Future = item.get('fut')
fut.cancel()
self._get_prop_list.clear()
if self._session and not self._session.closed:
await self._session.close()

View File

@ -71,7 +71,7 @@ class MIoTI18n:
) -> None:
self._main_loop = loop or asyncio.get_event_loop()
self._lang = lang
self._data = None
self._data = {}
async def init_async(self) -> None:
if self._data:
@ -94,7 +94,7 @@ class MIoTI18n:
self._data = data
async def deinit_async(self) -> None:
self._data = None
self._data = {}
def translate(
self, key: str, replace: Optional[dict[str, str]] = None

View File

@ -50,7 +50,7 @@ import base64
import binascii
import copy
from enum import Enum
from typing import Callable, Optional
from typing import Callable, Coroutine, Optional
import logging
from zeroconf import (
@ -98,8 +98,8 @@ class MipsServiceData:
def __init__(self, service_info: AsyncServiceInfo) -> None:
if service_info is None:
raise MipsServiceError('invalid params')
properties = service_info.decoded_properties
if properties is None:
properties: dict = service_info.decoded_properties
if not properties:
raise MipsServiceError('invalid service properties')
self.profile = properties.get('profile', None)
if self.profile is None:
@ -111,9 +111,11 @@ class MipsServiceData:
if not self.addresses:
raise MipsServiceError('invalid addresses')
self.addresses.sort()
if not service_info.port:
raise MipsServiceError('invalid port')
self.port = service_info.port
self.type = service_info.type
self.server = service_info.server
self.server = service_info.server or ''
# Parse profile
self.did = str(int.from_bytes(self.profile_bin[1:9]))
self.group_id = binascii.hexlify(
@ -150,8 +152,8 @@ class MipsService:
_aio_browser: AsyncServiceBrowser
_services: dict[str, dict]
# key = (key, group_id)
_sub_list: dict[(str, str), Callable[[
str, MipsServiceState, dict], asyncio.Future]]
_sub_list: dict[tuple[str, str], Callable[[
str, MipsServiceState, dict], Coroutine]]
def __init__(
self, aiozc: AsyncZeroconf,
@ -159,7 +161,6 @@ class MipsService:
) -> None:
self._aiozc = aiozc
self._main_loop = loop or asyncio.get_running_loop()
self._aio_browser = None
self._services = {}
self._sub_list = {}
@ -207,7 +208,7 @@ class MipsService:
def sub_service_change(
self, key: str, group_id: str,
handler: Callable[[str, MipsServiceState, dict], asyncio.Future]
handler: Callable[[str, MipsServiceState, dict], Coroutine]
) -> None:
if key is None or group_id is None or handler is None:
raise MipsServiceError('invalid params')
@ -232,7 +233,7 @@ class MipsService:
for item in list(self._services.values()):
if item['name'] != name:
continue
service_data = self._services.pop(item['group_id'], None)
service_data = self._services.pop(item['group_id'], {})
self.__call_service_change(
state=MipsServiceState.REMOVED, data=service_data)
return
@ -275,10 +276,10 @@ class MipsService:
_LOGGER.error('invalid mips service, %s, %s', error, info)
def __call_service_change(
self, state: MipsServiceState, data: dict = None
self, state: MipsServiceState, data: dict
) -> None:
_LOGGER.info('call service change, %s, %s', state, data)
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._sub_list[keys](data['group_id'], state, data))