feat: add notifications for the local connection to the central hub gateway (#1280)
Some checks failed
Tests / check-rule-format (push) Failing after 6s
Validate / validate-hassfest (push) Failing after 5s
Validate / validate-hacs (push) Failing after 11s
Validate / validate-lint (push) Failing after 3s
Validate / validate-setup (push) Failing after 7s

* feat: add notifications for the central hub gateway connection status (#1103)

* fix: i18n langurage support

* fix: add notification of disconnection when ServiceStateChange.REMOVED
This commit is contained in:
Li Shuzhen
2025-07-21 16:49:42 +08:00
committed by GitHub
parent 580ff87e7f
commit 0fee02ae5c
13 changed files with 69 additions and 1 deletions

View File

@ -1115,8 +1115,10 @@ class MIoTClient:
_LOGGER.info('local mips state changed, %s, %s', group_id, state)
mips = self._mips_local.get(group_id, None)
if not mips:
_LOGGER.error(
_LOGGER.info(
'local mips state changed, mips not exist, %s', group_id)
# The connection to the central hub gateway is definitely broken.
self.__show_central_state_changed_notify(False)
return
if state:
# Connected
@ -1150,6 +1152,7 @@ class MIoTClient:
if sub and sub.handler:
sub.handler(did, MIoTDeviceState.OFFLINE, sub.handler_ctx)
self.__request_show_devices_changed_notify()
self.__show_central_state_changed_notify(state)
@final
async def __on_miot_lan_state_change(self, state: bool) -> None:
@ -1915,6 +1918,23 @@ class MIoTClient:
self._show_devices_changed_notify_timer = self._main_loop.call_later(
delay_sec, self.__show_devices_changed_notify)
@final
def __show_central_state_changed_notify(self, connected: bool) -> None:
conn_status: str = (
self._i18n.translate('miot.client.central_state_connected')
if connected else
self._i18n.translate('miot.client.central_state_disconnected'))
self._persistence_notify(
self.__gen_notify_key('central_state_changed'),
self._i18n.translate('miot.client.central_state_changed_title'),
self._i18n.translate(key='miot.client.central_state_changed',
replace={
'nick_name': self._entry_data.get(
'nick_name', DEFAULT_NICK_NAME),
'uid': self._uid,
'cloud_server': self._cloud_server,
'conn_status': conn_status
}))
@staticmethod
async def get_miot_instance_async(