Skip to content

Commit

Permalink
fix: Resolve line length violations in config_flow.py
Browse files Browse the repository at this point in the history
- Shortened lines in custom_components/xiaomi_home/config_flow.py to comply with PEP 8's line length limit (80 characters).
- Addressed pylint warnings concerning line lengths on lines 489, 568, and 569.
  • Loading branch information
JimmyKmi committed Dec 19, 2024
1 parent b37a249 commit 5becfa2
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions custom_components/xiaomi_home/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(self) -> None:
self._storage_path = None
self._virtual_did = None
self._uid = None
self._uuid = None # MQTT client id
self._uuid = None # MQTT client id
self._ctrl_mode = None
self._area_name_rule = None
self._action_debug = False
Expand Down Expand Up @@ -348,7 +348,7 @@ async def __check_oauth_async(self) -> None:
).hexdigest()[:32]
try:
self._nick_name = (
await self._miot_http.get_user_info_async() or {}
await self._miot_http.get_user_info_async() or {}
).get('miliaoNick', DEFAULT_NICK_NAME)
except (MIoTOauthError, json.JSONDecodeError):
self._nick_name = DEFAULT_NICK_NAME
Expand Down Expand Up @@ -392,7 +392,7 @@ async def __check_oauth_async(self) -> None:
tip_devices = self._miot_i18n.translate(key='config.other.devices')
# home list
for home_id, home_info in self._home_info_buffer[
'homes']['home_list'].items():
'homes']['home_list'].items():
# i18n
tip_central = ''
group_id = home_info.get('group_id', None)
Expand All @@ -401,9 +401,9 @@ async def __check_oauth_async(self) -> None:
for device in list(self._home_info_buffer['devices'].values())
if device.get('home_id', None) == home_id}
if (
mips_list
and group_id in mips_list
and mips_list[group_id].get('did', None) in dev_list
mips_list
and group_id in mips_list
and mips_list[group_id].get('did', None) in dev_list
):
# i18n
tip_central = self._miot_i18n.translate(
Expand Down Expand Up @@ -486,7 +486,8 @@ async def async_step_devices_filter(self, user_input=None):
self._home_selected[home_id] = home_info
self._area_name_rule = user_input.get('area_name_rule')
# Check if advanced options should be shown
show_advanced_options = user_input.get('show_advanced_options', False)
show_advanced_options = user_input.get(
'show_advanced_options', False)
# Storage device list
devices_list: dict[str, dict] = {
did: dev_info
Expand Down Expand Up @@ -565,8 +566,10 @@ async def display_device_filter_form(self, reason: str):

async def async_step_advanced_options(self, user_input=None):
if user_input is not None:
# Advanced options, the default values are specified alongside the definition of each variable
self._action_debug = user_input.get('action_debug', self._action_debug)
# Advanced options, the default values are specified alongside
# the definition of each variable
self._action_debug = user_input.get(
'action_debug', self._action_debug)
self._hide_non_standard_entities = user_input.get(
'hide_non_standard_entities', self._hide_non_standard_entities)
return self.async_create_entry(
Expand Down Expand Up @@ -982,8 +985,8 @@ async def async_step_update_user_info(self, user_input=None):
return await self.async_step_devices_filter()
if not user_input:
nick_name_new = (
await self._miot_http.get_user_info_async() or {}).get(
'miliaoNick', DEFAULT_NICK_NAME)
await self._miot_http.get_user_info_async() or {}).get(
'miliaoNick', DEFAULT_NICK_NAME)
return self.async_show_form(
step_id='update_user_info',
data_schema=vol.Schema({
Expand Down Expand Up @@ -1024,7 +1027,7 @@ async def async_step_devices_filter(self, user_input=None):
tip_devices = self._miot_i18n.translate(key='config.other.devices')
# home list
for home_id, home_info in self._home_info_buffer[
'homes']['home_list'].items():
'homes']['home_list'].items():
# i18n
tip_central = ''
group_id = home_info.get('group_id', None)
Expand All @@ -1033,8 +1036,8 @@ async def async_step_devices_filter(self, user_input=None):
self._home_info_buffer['devices'].values())
if device.get('home_id', None) == home_id}
if (
group_id in mips_list
and mips_list[group_id].get('did', None) in did_list
group_id in mips_list
and mips_list[group_id].get('did', None) in did_list
):
# i18n
tip_central = self._miot_i18n.translate(
Expand All @@ -1058,7 +1061,7 @@ async def async_step_devices_filter(self, user_input=None):
self._ctrl_mode = user_input.get('ctrl_mode')
self._home_selected_dict = {}
for home_id, home_info in self._home_info_buffer[
'homes']['home_list'].items():
'homes']['home_list'].items():
if home_id in self._home_selected_list:
self._home_selected_dict[home_id] = home_info
# Get device list
Expand Down Expand Up @@ -1183,8 +1186,8 @@ async def async_step_update_lan_ctrl_config(self, user_input=None):
selected_if = lan_ctrl_config.get('net_interfaces', [])
enable_subscribe = lan_ctrl_config.get('enable_subscribe', False)
if (
set(selected_if_new) != set(selected_if)
or enable_subscribe_new != enable_subscribe
set(selected_if_new) != set(selected_if)
or enable_subscribe_new != enable_subscribe
):
if not await self._miot_storage.update_user_config_async(
'global_config', 'all', {
Expand Down Expand Up @@ -1243,7 +1246,7 @@ async def async_step_config_confirm(self, user_input=None):
self._entry_data['home_selected'] = self._home_selected_dict
devices_list_sort = dict(sorted(
self._device_list.items(), key=lambda item:
item[1].get('home_id', '')+item[1].get('room_id', '')))
item[1].get('home_id', '') + item[1].get('room_id', '')))
if not await self._miot_storage.save_async(
domain='miot_devices',
name=f'{self._uid}_{self._cloud_server}',
Expand All @@ -1261,18 +1264,18 @@ async def async_step_config_confirm(self, user_input=None):
self._entry_data['action_debug'] = self._action_debug_new
self._need_reload = True
if (
self._hide_non_standard_entities_new !=
self._hide_non_standard_entities
self._hide_non_standard_entities_new !=
self._hide_non_standard_entities
):
self._entry_data['hide_non_standard_entities'] = (
self._hide_non_standard_entities_new)
self._need_reload = True
if (
self._devices_remove
and not await self._miot_storage.update_user_config_async(
uid=self._uid,
cloud_server=self._cloud_server,
config={'devices_remove': self._devices_remove})
uid=self._uid,
cloud_server=self._cloud_server,
config={'devices_remove': self._devices_remove})
):
raise AbortFlow(
reason='storage_error',
Expand Down

0 comments on commit 5becfa2

Please sign in to comment.