refactor: refactor miot device and spec (#592)

* fix: fix miot_device type error

* fix: fix type error

* feat: remove spec cache storage

* feat: update std_lib and multi_lang logic

* feat: update entity value-range

* feat: update value-list logic

* feat: update prop.format_ logic

* fix: fix miot cloud log error

* fix: fix fan entity

* style: ignore type error

* style: rename spec_filter func name

* feat: move bool_trans from storage to spec

* feat: move sepc_filter from storage to spec, use the YAML format file

* feat: same prop supports multiple sub

* feat: same event supports multiple sub

* fix: fix device remove error

* feat: add func slugify_did

* fix: fix multi lang error

* feat: update action debug logic

* feat: ignore normal disconnect log

* feat: support binary mode

* feat: change miot spec name type define

* style: ignore i18n tranlate type error

* fix: fix pylint warning

* fix: miot storage type error

* feat: support binary display mode configure

* feat: set default sensor state_class

* fix: fix sensor entity type error

* fix: fix __init__ type error

* feat: update test case logic

* fix: github actions add dependencies lib

* fix: fix some type error

* feat: update device list changed notify logic
This commit is contained in:
Paul Shawn
2025-01-17 18:14:31 +08:00
committed by GitHub
parent bf116e13a4
commit ef56448dbb
54 changed files with 2050 additions and 1978 deletions

View File

@ -124,6 +124,7 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
_area_name_rule: str
_action_debug: bool
_hide_non_standard_entities: bool
_display_binary_mode: list[str]
_display_devices_changed_notify: list[str]
_cloud_server: str
@ -158,6 +159,7 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._area_name_rule = self.DEFAULT_AREA_NAME_RULE
self._action_debug = False
self._hide_non_standard_entities = False
self._display_binary_mode = ['bool']
self._display_devices_changed_notify = ['add', 'del', 'offline']
self._auth_info = {}
self._nick_name = DEFAULT_NICK_NAME
@ -473,6 +475,7 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
await self._miot_oauth.deinit_async()
self._miot_oauth = None
return self.async_show_progress_done(next_step_id='homes_select')
# pylint: disable=unexpected-keyword-arg
return self.async_show_progress(
step_id='oauth',
progress_action='oauth',
@ -481,7 +484,7 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
f'<a href="{self._cc_oauth_auth_url}" target="_blank">',
'link_right': '</a>'
},
progress_task=self._cc_task_oauth,
progress_task=self._cc_task_oauth, # type: ignore
)
async def __check_oauth_async(self) -> None:
@ -727,6 +730,8 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
'action_debug', self._action_debug)
self._hide_non_standard_entities = user_input.get(
'hide_non_standard_entities', self._hide_non_standard_entities)
self._display_binary_mode = user_input.get(
'display_binary_mode', self._display_binary_mode)
self._display_devices_changed_notify = user_input.get(
'display_devices_changed_notify',
self._display_devices_changed_notify)
@ -749,6 +754,12 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
'hide_non_standard_entities',
default=self._hide_non_standard_entities # type: ignore
): bool,
vol.Required(
'display_binary_mode',
default=self._display_binary_mode # type: ignore
): cv.multi_select(
self._miot_i18n.translate(
key='config.binary_mode')), # type: ignore
vol.Required(
'display_devices_changed_notify',
default=self._display_devices_changed_notify # type: ignore
@ -931,6 +942,7 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
'action_debug': self._action_debug,
'hide_non_standard_entities':
self._hide_non_standard_entities,
'display_binary_mode': self._display_binary_mode,
'display_devices_changed_notify':
self._display_devices_changed_notify
})
@ -972,6 +984,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
_devices_filter: dict
_action_debug: bool
_hide_non_standard_entities: bool
_display_binary_mode: list[str]
_display_devs_notify: list[str]
_oauth_redirect_url_full: str
@ -986,6 +999,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
_nick_name_new: Optional[str]
_action_debug_new: bool
_hide_non_standard_entities_new: bool
_display_binary_mode_new: list[str]
_update_user_info: bool
_update_devices: bool
_update_trans_rules: bool
@ -1024,6 +1038,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
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_binary_mode = self._entry_data.get(
'display_binary_mode', ['text'])
self._display_devs_notify = self._entry_data.get(
'display_devices_changed_notify', ['add', 'del', 'offline'])
self._home_selected_list = list(
@ -1042,6 +1058,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
self._nick_name_new = None
self._action_debug_new = False
self._hide_non_standard_entities_new = False
self._display_binary_mode_new = []
self._update_user_info = False
self._update_devices = False
self._update_trans_rules = False
@ -1196,7 +1213,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
err, traceback.format_exc())
self._cc_config_rc = str(err)
return self.async_show_progress_done(next_step_id='oauth_error')
# pylint: disable=unexpected-keyword-arg
return self.async_show_progress(
step_id='oauth',
progress_action='oauth',
@ -1205,7 +1222,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
f'<a href="{self._cc_oauth_auth_url}" target="_blank">',
'link_right': '</a>'
},
progress_task=self._cc_task_oauth,
progress_task=self._cc_task_oauth, # type: ignore
)
async def __check_oauth_async(self) -> None:
@ -1308,6 +1325,12 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
'hide_non_standard_entities',
default=self._hide_non_standard_entities # type: ignore
): bool,
vol.Required(
'display_binary_mode',
default=self._display_binary_mode # type: ignore
): cv.multi_select(
self._miot_i18n.translate(
'config.binary_mode')), # type: ignore
vol.Required(
'update_trans_rules',
default=self._update_trans_rules # type: ignore
@ -1336,6 +1359,8 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
'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_binary_mode_new = user_input.get(
'display_binary_mode', self._display_binary_mode)
self._display_devs_notify = user_input.get(
'display_devices_changed_notify', self._display_devs_notify)
self._update_trans_rules = user_input.get(
@ -1939,6 +1964,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
self._entry_data['hide_non_standard_entities'] = (
self._hide_non_standard_entities_new)
self._need_reload = True
if set(self._display_binary_mode) != set(self._display_binary_mode_new):
self._entry_data['display_binary_mode'] = (
self._display_binary_mode_new)
self._need_reload = True
# Update display_devices_changed_notify
self._entry_data['display_devices_changed_notify'] = (
self._display_devs_notify)