Skip to content

Commit

Permalink
feat: custom display device changed notify
Browse files Browse the repository at this point in the history
  • Loading branch information
topsworld committed Dec 24, 2024
1 parent 9eaa1e2 commit aa0400e
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 14 deletions.
20 changes: 20 additions & 0 deletions custom_components/xiaomi_home/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ async def async_step_advanced_options(
'action_debug', self._action_debug)
self._hide_non_standard_entities = user_input.get(
'hide_non_standard_entities', self._hide_non_standard_entities)
self._display_devices_changed_notify = user_input.get(
'display_devices_changed_notify',
self._display_devices_changed_notify)
# Device filter
if user_input.get('devices_filter', False):
return await self.async_step_devices_filter()
Expand Down Expand Up @@ -811,6 +814,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
_home_selected_list: list
_action_debug: bool
_hide_non_standard_entities: bool
_display_devs_notify: bool

_oauth_redirect_url_full: str
_auth_info: dict
Expand Down Expand Up @@ -856,6 +860,8 @@ def __init__(self, config_entry: config_entries.ConfigEntry):
self._action_debug = self._entry_data.get('action_debug', False)
self._hide_non_standard_entities = self._entry_data.get(
'hide_non_standard_entities', False)
self._display_devs_notify = self._entry_data.get(
'display_devices_changed_notify', True)
self._home_selected_list = list(
self._entry_data['home_selected'].keys())

Expand Down Expand Up @@ -1118,6 +1124,10 @@ async def async_step_config_options(self, user_input=None):
'hide_non_standard_entities',
default=self._hide_non_standard_entities # type: ignore
): bool,
vol.Required(
'display_devices_changed_notify',
default=self._display_devs_notify # type: ignore
): bool,
vol.Required(
'update_trans_rules',
default=self._update_trans_rules # type: ignore
Expand Down Expand Up @@ -1149,6 +1159,8 @@ async def async_step_config_options(self, user_input=None):
'action_debug', self._action_debug)
self._hide_non_standard_entities_new = user_input.get(
'hide_non_standard_entities', self._hide_non_standard_entities)
self._display_devs_notify = user_input.get(
'display_devices_changed_notify', self._display_devs_notify)
self._update_trans_rules = user_input.get(
'update_trans_rules', self._update_trans_rules)
self._update_lan_ctrl_config = user_input.get(
Expand Down Expand Up @@ -1554,6 +1566,9 @@ async def async_step_config_confirm(self, user_input=None):
'hide_non_standard_entities': (
enable_text if self._hide_non_standard_entities_new
else disable_text),
'display_devices_changed_notify': (
enable_text if self._display_devs_notify
else disable_text)
}, # type: ignore
errors={'base': 'not_confirm'} if user_input else {},
last_step=True
Expand Down Expand Up @@ -1590,6 +1605,11 @@ async def async_step_config_confirm(self, user_input=None):
self._entry_data['hide_non_standard_entities'] = (
self._hide_non_standard_entities_new)
self._need_reload = True
# Update display_devices_changed_notify
self._entry_data['display_devices_changed_notify'] = (
self._display_devs_notify)
self._miot_client.display_devices_changed_notify = (
self._display_devs_notify)
if (
self._devices_remove
and not await self._miot_storage.update_user_config_async(
Expand Down
24 changes: 23 additions & 1 deletion custom_components/xiaomi_home/miot/miot_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ 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_devs_notify: bool

def __init__(
self,
entry_id: str,
Expand Down Expand Up @@ -231,6 +233,9 @@ def __init__(
self._persistence_notify = None
self._show_devices_changed_notify_timer = None

self._display_devs_notify = entry_data.get(
'display_devices_changed_notify', True)

async def init_async(self) -> None:
# Load user config and check
self._user_config = await self._storage.load_user_config_async(
Expand Down Expand Up @@ -459,6 +464,21 @@ def hide_non_standard_entities(self) -> bool:
return self._entry_data.get(
'hide_non_standard_entities', False)

@property
def display_devices_changed_notify(self) -> bool:
return self._display_devs_notify

@display_devices_changed_notify.setter
def display_devices_changed_notify(self, value: bool) -> None:
if value == 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
Expand Down Expand Up @@ -1801,6 +1821,8 @@ def __show_devices_changed_notify(self) -> None:
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:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Bestätigen Sie die Konfiguration",
"description": "**{nick_name}**, bitte bestätigen Sie die neuesten Konfigurationsinformationen und klicken Sie dann auf \"Senden\". Die Integration wird mit den aktualisierten Konfigurationen erneut geladen.\r\n\r\nIntegrationsprache:\t{lang_new}\r\nBenutzername:\t{nick_name_new}\r\nAction-Debug-Modus:\t{action_debug}\r\nVerstecke Nicht-Standard-Entitäten:\t{hide_non_standard_entities}\r\nGeräteänderungen:\t{devices_add} neue Geräte hinzufügen, {devices_remove} Geräte entfernen\r\nKonvertierungsregeländerungen:\tInsgesamt {trans_rules_count} Regeln, aktualisiert {trans_rules_count_success} Regeln",
"description": "**{nick_name}**, bitte bestätigen Sie die neuesten Konfigurationsinformationen und klicken Sie dann auf \"Senden\". Die Integration wird mit den aktualisierten Konfigurationen erneut geladen.\r\n\r\nIntegrationsprache:\t{lang_new}\r\nBenutzername:\t{nick_name_new}\r\nAction-Debug-Modus:\t{action_debug}\r\nVerstecke Nicht-Standard-Entitäten:\t{hide_non_standard_entities}\r\nGerätestatusänderungen anzeigen:\t{display_devices_changed_notify}\r\nGeräteänderungen:\t{devices_add} neue Geräte hinzufügen, {devices_remove} Geräte entfernen\r\nKonvertierungsregeländerungen:\tInsgesamt {trans_rules_count} Regeln, aktualisiert {trans_rules_count_success} Regeln",
"data": {
"confirm": "Änderungen bestätigen"
}
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_home/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"ctrl_mode": "Control Mode",
"action_debug": "Action Debug Mode",
"hide_non_standard_entities": "Hide Non-Standard Generated Entities",
"display_devices_changed_notify": "Display Device Status Change Notification"
"display_devices_changed_notify": "Display Device Status Change Notifications"
}
},
"devices_filter": {
Expand Down Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Confirm Configuration",
"description": "Hello **{nick_name}**, please confirm the latest configuration information and then Click SUBMIT.\r\nThe integration will reload using the updated configuration.\r\n\r\nIntegration Language: \t{lang_new}\r\nNickname: \t{nick_name_new}\r\nDebug mode for action: \t{action_debug}\r\nHide non-standard created entities: \t{hide_non_standard_entities}\r\nDevice Changes: \tAdd **{devices_add}** devices, Remove **{devices_remove}** devices\r\nTransformation rules change: \tThere are a total of **{trans_rules_count}** rules, and updated **{trans_rules_count_success}** rules",
"description": "Hello **{nick_name}**, please confirm the latest configuration information and then Click SUBMIT.\r\nThe integration will reload using the updated configuration.\r\n\r\nIntegration Language: \t{lang_new}\r\nNickname: \t{nick_name_new}\r\nDebug mode for action: \t{action_debug}\r\nHide non-standard created entities: \t{hide_non_standard_entities}\r\nDisplay device status change notifications:\t{display_devices_changed_notify}\r\nDevice Changes: \tAdd **{devices_add}** devices, Remove **{devices_remove}** devices\r\nTransformation rules change: \tThere are a total of **{trans_rules_count}** rules, and updated **{trans_rules_count_success}** rules",
"data": {
"confirm": "Confirm the change"
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Confirmar configuración",
"description": "¡Hola, **{nick_name}**! Por favor, confirme la última información de configuración y haga clic en \"Enviar\" para finalizar la configuración.\r\nLa integración se volverá a cargar con la nueva configuración.\r\n\r\nIdioma de la integración:\t{lang_new}\r\nApodo de usuario:\t{nick_name_new}\r\nModo de depuración de Action:\t{action_debug}\r\nOcultar entidades generadas no estándar:\t{hide_non_standard_entities}\r\nCambios de dispositivos:\t{devices_add} dispositivos agregados, {devices_remove} dispositivos eliminados\r\nCambios en las reglas de conversión:\t{trans_rules_count} reglas en total, {trans_rules_count_success} reglas actualizadas",
"description": "¡Hola, **{nick_name}**! Por favor, confirme la última información de configuración y haga clic en \"Enviar\" para finalizar la configuración.\r\nLa integración se volverá a cargar con la nueva configuración.\r\n\r\nIdioma de la integración:\t{lang_new}\r\nApodo de usuario:\t{nick_name_new}\r\nModo de depuración de Action:\t{action_debug}\r\nOcultar entidades generadas no estándar:\t{hide_non_standard_entities}\r\nMostrar notificaciones de cambio de estado del dispositivo:\t{display_devices_changed_notify}\r\nCambios de dispositivos:\t{devices_add} dispositivos agregados, {devices_remove} dispositivos eliminados\r\nCambios en las reglas de conversión:\t{trans_rules_count} reglas en total, {trans_rules_count_success} reglas actualizadas",
"data": {
"confirm": "Confirmar modificación"
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Confirmer la configuration",
"description": "**{nick_name}** Bonjour ! Veuillez confirmer les dernières informations de configuration et cliquer sur \"Soumettre\".\r\nL'intégration rechargera avec la nouvelle configuration.\r\n\r\nLangue d'intégration : {lang_new}\r\nPseudo utilisateur : {nick_name_new}\r\nMode de débogage d'action : {action_debug}\r\nMasquer les entités générées non standard : {hide_non_standard_entities}\r\nModifications des appareils : Ajouter **{devices_add}** appareils, supprimer **{devices_remove}** appareils\r\nModifications des règles de conversion : **{trans_rules_count}** règles au total, mise à jour de **{trans_rules_count_success}** règles",
"description": "**{nick_name}** Bonjour ! Veuillez confirmer les dernières informations de configuration et cliquer sur \"Soumettre\".\r\nL'intégration rechargera avec la nouvelle configuration.\r\n\r\nLangue d'intégration : {lang_new}\r\nPseudo utilisateur : {nick_name_new}\r\nMode de débogage d'action : {action_debug}\r\nMasquer les entités générées non standard : {hide_non_standard_entities}\r\nAfficher les notifications de changement d'état de l'appareil:\t{display_devices_changed_notify}\r\nModifications des appareils : Ajouter **{devices_add}** appareils, supprimer **{devices_remove}** appareils\r\nModifications des règles de conversion : **{trans_rules_count}** règles au total, mise à jour de **{trans_rules_count_success}** règles",
"data": {
"confirm": "Confirmer la modification"
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "構成を確認する",
"description": "**{nick_name}** さん、こんにちは! 最新の構成情報を確認してください。[送信] をクリックして、更新された構成を使用して再度読み込みます。\r\n\r\n統合言語:\t{lang_new}\r\nユーザー名:\t{nick_name_new}\r\nAction デバッグモード:\t{action_debug}\r\n非標準生成エンティティを非表示にする:\t{hide_non_standard_entities}\r\nデバイス変更:\t追加 **{devices_add}** 個のデバイス、削除 **{devices_remove}** 個のデバイス\r\n変換ルール変更:\t合計 **{trans_rules_count}** 個の規則、更新 **{trans_rules_count_success}** 個の規則",
"description": "**{nick_name}** さん、こんにちは! 最新の構成情報を確認してください。[送信] をクリックして、更新された構成を使用して再度読み込みます。\r\n\r\n統合言語:\t{lang_new}\r\nユーザー名:\t{nick_name_new}\r\nAction デバッグモード:\t{action_debug}\r\n非標準生成エンティティを非表示にする:\t{hide_non_standard_entities}\r\nデバイスの状態変化通知を表示:\t{display_devices_changed_notify}\r\nデバイス変更:\t追加 **{devices_add}** 個のデバイス、削除 **{devices_remove}** 個のデバイス\r\n変換ルール変更:\t合計 **{trans_rules_count}** 個の規則、更新 **{trans_rules_count_success}** 個の規則",
"data": {
"confirm": "変更を確認する"
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Bevestig Configuratie",
"description": "Hallo **{nick_name}**, bevestig alstublieft de nieuwste configuratie-informatie en klik vervolgens op INDENKEN.\r\nDe integratie zal opnieuw laden met de bijgewerkte configuratie.\r\n\r\nIntegratietaal: \t{lang_new}\r\nBijnaam: \t{nick_name_new}\r\nDebugmodus voor actie: \t{action_debug}\r\nVerberg niet-standaard gemaakte entiteiten: \t{hide_non_standard_entities}\r\nWijzigingen in apparaten: \tVoeg **{devices_add}** apparaten toe, Verwijder **{devices_remove}** apparaten\r\nWijzigingen in transformateregels: \tEr zijn in totaal **{trans_rules_count}** regels, en **{trans_rules_count_success}** regels zijn bijgewerkt",
"description": "Hallo **{nick_name}**, bevestig alstublieft de nieuwste configuratie-informatie en klik vervolgens op INDENKEN.\r\nDe integratie zal opnieuw laden met de bijgewerkte configuratie.\r\n\r\nIntegratietaal: \t{lang_new}\r\nBijnaam: \t{nick_name_new}\r\nDebugmodus voor actie: \t{action_debug}\r\nVerberg niet-standaard gemaakte entiteiten: \t{hide_non_standard_entities}\r\nApparaatstatuswijzigingen weergeven:\t{display_devices_changed_notify}\r\nWijzigingen in apparaten: \tVoeg **{devices_add}** apparaten toe, Verwijder **{devices_remove}** apparaten\r\nWijzigingen in transformateregels: \tEr zijn in totaal **{trans_rules_count}** regels, en **{trans_rules_count_success}** regels zijn bijgewerkt",
"data": {
"confirm": "Bevestig de wijziging"
}
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_home/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"ctrl_mode": "Modo de Controle",
"action_debug": "Modo de Depuração de Ações",
"hide_non_standard_entities": "Ocultar Entidades Geradas Não Padrão",
"display_devices_changed_notify": "Exibir notificações de mudança de status do dispositivo",
"display_devices_changed_notify": "Exibir notificações de mudança de status do dispositivo"
}
},
"devices_filter": {
Expand Down Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Confirmar Configuração",
"description": "Olá **{nick_name}**, confirme as informações da configuração mais recente e depois clique em ENVIAR.\r\nA integração será recarregada com a configuração atualizada.\r\n\r\nIdioma da Integração:\t{lang_new}\r\nApelido:\t{nick_name_new}\r\nModo de depuração para ação:\t{action_debug}\r\nOcultar entidades não padrão criadas:\t{hide_non_standard_entities}\r\nAlterações de Dispositivos:\tAdicionar **{devices_add}** dispositivos, Remover **{devices_remove}** dispositivos\r\nAlteração nas Regras de Transformação:\tUm total de **{trans_rules_count}** regras, e **{trans_rules_count_success}** regras atualizadas",
"description": "Olá **{nick_name}**, confirme as informações da configuração mais recente e depois clique em ENVIAR.\r\nA integração será recarregada com a configuração atualizada.\r\n\r\nIdioma da Integração:\t{lang_new}\r\nApelido:\t{nick_name_new}\r\nModo de depuração para ação:\t{action_debug}\r\nOcultar entidades não padrão criadas:\t{hide_non_standard_entities}\r\nExibir notificações de mudança de status do dispositivo:\t{display_devices_changed_notify}\r\nAlterações de Dispositivos:\tAdicionar **{devices_add}** dispositivos, Remover **{devices_remove}** dispositivos\r\nAlteração nas Regras de Transformação:\tUm total de **{trans_rules_count}** regras, e **{trans_rules_count_success}** regras atualizadas",
"data": {
"confirm": "Confirmar a mudança"
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_home/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"config_confirm": {
"title": "Confirmar Configuração",
"description": "Olá **{nick_name}**, confirme a informação da configuração mais recente e depois clique em SUBMETER.\r\nA integração será recarregada com a configuração atualizada.\r\n\r\nIdioma da Integração:\t{lang_new}\r\nAlcunha:\t{nick_name_new}\r\nModo de depuração de ação:\t{action_debug}\r\nOcultar entidades não padrão:\t{hide_non_standard_entities}\r\nAlterações aos Dispositivos:\tAdicionar **{devices_add}** dispositivos, Remover **{devices_remove}** dispositivos\r\nAlteração das Regras de Transformação:\tExistem **{trans_rules_count}** regras no total, com **{trans_rules_count_success}** regras atualizadas",
"description": "Olá **{nick_name}**, confirme a informação da configuração mais recente e depois clique em SUBMETER.\r\nA integração será recarregada com a configuração atualizada.\r\n\r\nIdioma da Integração:\t{lang_new}\r\nAlcunha:\t{nick_name_new}\r\nModo de depuração de ação:\t{action_debug}\r\nOcultar entidades não padrão:\t{hide_non_standard_entities}\r\nExibir notificações de mudança de status do dispositivo:\t{display_devices_changed_notify}\r\nAlterações aos Dispositivos:\tAdicionar **{devices_add}** dispositivos, Remover **{devices_remove}** dispositivos\r\nAlteração das Regras de Transformação:\tExistem **{trans_rules_count}** regras no total, com **{trans_rules_count_success}** regras atualizadas",
"data": {
"confirm": "Confirmar a alteração"
}
Expand Down
Loading

0 comments on commit aa0400e

Please sign in to comment.