mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2025-08-02 21:39:16 +08:00
feat: add notifications for the local connection to the central hub gateway (#1280)
Some checks failed
Some checks failed
* 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:
@ -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(
|
||||
|
Reference in New Issue
Block a user