Skip to content

Commit

Permalink
🔃 add renew_devices option
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Mar 12, 2021
1 parent 638090f commit dfe967c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions custom_components/xiaomi_miot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ async def check_miio_device(hass, user_input, errors):
return user_input


async def check_xiaomi_account(hass, user_input, errors):
async def check_xiaomi_account(hass, user_input, errors, renew_devices=False):
dvs = []
try:
mic = await MiotCloud.from_token(hass, user_input)
if not mic:
raise MiCloudException('Login failed')
user_input['xiaomi_cloud'] = mic
dvs = await mic.async_get_devices() or []
dvs = await mic.async_get_devices(renew=renew_devices) or []
except MiCloudException as exc:
errors['base'] = 'cannot_login'
_LOGGER.error('Setup xiaomi cloud for user: %s failed: %s', user_input.get(CONF_USERNAME), exc)
Expand Down Expand Up @@ -276,7 +276,8 @@ async def async_step_cloud(self, user_input=None):
errors = {}
if isinstance(user_input, dict):
user_input = {**self.config_entry.data, **self.config_entry.options, **user_input}
await check_xiaomi_account(self.hass, user_input, errors)
renew = user_input.get('renew_devices') and True
await check_xiaomi_account(self.hass, user_input, errors, renew_devices=renew)
if not errors:
return await self.async_step_cloud_filter(user_input)
else:
Expand All @@ -288,6 +289,7 @@ async def async_step_cloud(self, user_input=None):
vol.Required(CONF_PASSWORD, default=user_input.get(CONF_PASSWORD, vol.UNDEFINED)): str,
vol.Required('server_country', default=user_input.get('server_country', 'cn')):
vol.In(CLOUD_SERVERS),
vol.Optional('renew_devices', default=user_input.get('renew_devices', False)): bool,
}),
errors=errors,
)
Expand Down
3 changes: 2 additions & 1 deletion custom_components/xiaomi_miot/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"data": {
"username": "Xiaomi Account ID / Email",
"password": "Password",
"server_country": "Server location of MiCloud"
"server_country": "Server location of MiCloud",
"renew_devices": "Force renew devices"
}
},
"cloud_filter": {
Expand Down
3 changes: 2 additions & 1 deletion custom_components/xiaomi_miot/translations/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"data": {
"username": "小米ID / 邮箱",
"password": "小米密码",
"server_country": "小米服务器"
"server_country": "小米服务器",
"renew_devices": "更新设备列表"
}
},
"cloud_filter": {
Expand Down

0 comments on commit dfe967c

Please sign in to comment.