Compare commits

...

11 Commits

Author SHA1 Message Date
KNOOP
c6eeaf49e6
Merge d797f1faa7 into 9af59e28bd 2024-12-24 02:27:01 +05:00
Li Shuzhen
9af59e28bd
docs: specify the download process in HACS installation (#371)
Some checks are pending
Tests / check-rule-format (push) Waiting to run
Validate / validate-hassfest (push) Waiting to run
Validate / validate-hacs (push) Waiting to run
Validate / validate-lint (push) Waiting to run
Validate / validate-setup (push) Waiting to run
* docs: specify the download process in HACS installation

* docs: revoke login authorization
2024-12-23 22:40:57 +08:00
KNOOP
d797f1faa7
Update config_flow.py 2024-12-19 18:30:28 +08:00
KNOOP
fdd4da19f6
Update zh-Hans.json 2024-12-19 18:28:08 +08:00
KNOOP
5f86cdb28d
Update en.json 2024-12-19 17:43:50 +08:00
KNOOP
daf7d2a4fe
Update zh-Hant.json 2024-12-19 17:43:17 +08:00
KNOOP
fb83d0ab0c
Update zh-Hans.json 2024-12-19 17:42:18 +08:00
KNOOP
c6707225ce
Update en.json 2024-12-19 17:31:27 +08:00
KNOOP
d0a8007d36
Update zh-Hant.json 2024-12-19 17:30:37 +08:00
KNOOP
e65aea145e
Update zh-Hans.json 2024-12-19 17:29:47 +08:00
KNOOP
4c63d2e5ac
Update config_flow.py 2024-12-19 17:27:01 +08:00
6 changed files with 65 additions and 13 deletions

View File

@ -32,7 +32,7 @@ git checkout v1.0.0
### Method 2: [HACS](https://hacs.xyz/)
HACS > Overflow Menu > Custom repositories > Repository: https://github.com/XiaoMi/ha_xiaomi_home.git & Category: Integration > ADD
HACS > Overflow Menu > Custom repositories > Repository: https://github.com/XiaoMi/ha_xiaomi_home.git & Category: Integration > ADD > Xiaomi Home in New or Available for download section of HACS > DOWNLOAD
> Xiaomi Home has not been added to the HACS store as a default yet. It's coming soon.
@ -76,6 +76,8 @@ Method: [Settings > Devices & services > Configured > Xiaomi Home](https://my.ho
Xiaomi Home Integration and the affiliated cloud interface is provided by Xiaomi officially. You need to use your Xiaomi account to login to get your device list. Xiaomi Home Integration implements OAuth 2.0 login process, which does not keep your account password in the Home Assistant application. However, due to the limitation of the Home Assistant platform, the user information (including device information, certificates, tokens, etc.) of your Xiaomi account will be saved in the Home Assistant configuration file in clear text after successful login. You need to ensure that your Home Assistant configuration file is properly stored. The exposure of your configuration file may result in others logging in with your identity.
> If you suspect that your OAuth 2.0 token has been leaked, you can revoke the login authorization of your Xiaomi account by the following steps: Xiaomi Home APP -> Profile -> Click your username and get into Xiaomi Account management page -> Basic info: Apps -> Xiaomi Home (Home Assistant Integration) -> Remove
## FAQ
- Does Xiaomi Home Integration support all Xiaomi Home devices?

View File

@ -50,7 +50,7 @@ import hashlib
import json
import secrets
import traceback
from typing import Optional
from typing import Any, Optional
from aiohttp import web
from aiohttp.hdrs import METH_GET
import voluptuous as vol
@ -59,6 +59,8 @@ import logging
from homeassistant import config_entries
from homeassistant.components import zeroconf
from homeassistant.components.zeroconf import HaAsyncZeroconf
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_RECONFIGURE
from homeassistant.config_entries import FlowResult
from homeassistant.components.webhook import (
async_register as webhook_async_register,
async_unregister as webhook_async_unregister,
@ -68,6 +70,7 @@ from homeassistant.core import callback
from homeassistant.data_entry_flow import AbortFlow
import homeassistant.helpers.config_validation as cv
from .miot.const import (
DEFAULT_CLOUD_SERVER,
DEFAULT_CTRL_MODE,
@ -383,8 +386,9 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
# TASK 4: Abort if unique_id configured
# Each MiHome account can only configure one instance
await self.async_set_unique_id(f'{self._cloud_server}{self._uid}')
self._abort_if_unique_id_configured()
if self.source not in (SOURCE_REAUTH, SOURCE_RECONFIGURE):
self._abort_if_unique_id_configured()
# TASK 5: Query mdns info
mips_list = None
if self._cloud_server in SUPPORT_CENTRAL_GATEWAY_CTRL:
@ -525,6 +529,22 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
'auth_info': self._auth_info
})):
raise MIoTError('miot_storage.update_user_config_async error')
if self.source in (SOURCE_REAUTH, SOURCE_RECONFIGURE):
entry = self._get_reauth_entry() if self.source == SOURCE_REAUTH else self._get_reconfigure_entry()
if user_input:
data_updates = {
"ctrl_mode": self._ctrl_mode,
"home_selected": self._home_selected,
"area_name_rule": self._area_name_rule,
"action_debug": self._action_debug,
"hide_non_standard_entities": self._hide_non_standard_entities,
}
devices_list_sort = dict(sorted(devices_list.items(), key=lambda item: 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}', data=devices_list_sort):
return self.async_abort(reason="storage_error")
return self.async_update_reload_and_abort(entry=entry, data_updates=data_updates, reason="reconfigure_successful")
return self.async_create_entry(
title=(
f'{self._nick_name}: {self._uid} '
@ -575,15 +595,37 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
},
last_step=False,
)
async def async_step_reauth(self, entry_data: dict[str, Any]) -> FlowResult:
"""Handle reauthorization request."""
entry = self._get_reauth_entry()
self._virtual_did = entry.data["virtual_did"]
self._uid = entry.data["uid"]
self._storage_path = entry.data["storage_path"]
self._cloud_server = entry.data["cloud_server"]
self._integration_language = entry.data["integration_language"]
await self.async_set_unique_id(f'{self._cloud_server}{self._uid}')
self._abort_if_unique_id_mismatch()
@staticmethod
@callback
return await self.async_step_auth_config()
async def async_step_reconfigure(self, entry_data: dict[str, Any]) -> FlowResult:
"""Handle a reconfigure flow."""
# For reconfigure, just start from the beginning like a new setup
return await self.async_step_user()
@ staticmethod
@ callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> config_entries.OptionsFlow:
return OptionsFlowHandler(config_entry)
class OptionsFlowHandler(config_entries.OptionsFlow):
"""Xiaomi MiHome options flow."""
# pylint: disable=unused-argument

View File

@ -51,7 +51,9 @@
"network_connect_error": "Configuration failed. The network connection is abnormal. Please check the equipment network configuration.",
"already_configured": "Configuration for this user is already completed. Please go to the integration page and click the CONFIGURE button for modifications.",
"invalid_auth_info": "Authentication information has expired. Please go to the integration page and click the CONFIGURE button to re-authenticate.",
"config_flow_error": "Integration configuration error: {error}."
"config_flow_error": "Integration configuration error: {error}.",
"reauth_failed": "Re-authorization failed",
"reconfigure_successful": "Reconfiguration successful"
}
},
"options": {
@ -141,4 +143,4 @@
"inconsistent_account": "Account information is inconsistent. Please login with the correct account."
}
}
}
}

View File

@ -51,7 +51,9 @@
"network_connect_error": "配置失败。网络连接异常,请检查设备网络配置。",
"already_configured": "该用户已配置完成。请进入集成页面,点击“配置”按钮修改配置。",
"invalid_auth_info": "认证信息已过期。请进入集成页面,点击“配置”按钮重新认证。",
"config_flow_error": "集成配置错误:{error}"
"config_flow_error": "集成配置错误:{error}",
"reauth_failed": "重新授权失败",
"reconfigure_successful": "重新配置成功"
}
},
"options": {
@ -141,4 +143,4 @@
"inconsistent_account": "账号信息不一致。请使用正确的账号登录。"
}
}
}
}

View File

@ -51,7 +51,9 @@
"network_connect_error": "配置失敗。網絡連接異常,請檢查設備網絡配置。",
"already_configured": "該用戶已配置完成。請進入集成頁面,點擊“配置”按鈕修改配置。",
"invalid_auth_info": "認證信息已過期。請進入集成頁面,點擊“配置”按鈕重新認證。",
"config_flow_error": "集成配置錯誤:{error}"
"config_flow_error": "集成配置錯誤:{error}",
"reauth_failed": "重新授權失敗",
"reconfigure_successful": "重新配置成功"
}
},
"options": {
@ -141,4 +143,4 @@
"inconsistent_account": "帳號信息不一致。請使用正確的帳號登錄。"
}
}
}
}

View File

@ -32,7 +32,7 @@ git checkout v1.0.0
### 方法 2: [HACS](https://hacs.xyz/)
HACS > Overflow Menu > Custom repositories > Repository: https://github.com/XiaoMi/ha_xiaomi_home.git & Category: Integration > ADD
HACS > 右上角三个点 > Custom repositories > Repository: https://github.com/XiaoMi/ha_xiaomi_home.git & Category: Integration > ADD > 点击 HACS 的 New 或 Available for download 分类下的 Xiaomi Home ,进入集成详情页 > DOWNLOAD
> 米家集成暂未添加到 HACS 商店,敬请期待。
@ -76,6 +76,8 @@ HACS > Overflow Menu > Custom repositories > Repository: https://github.com/Xiao
米家集成及其使用的云端接口由小米官方提供。您需要使用小米账号登录以获取设备列表。米家集成使用 OAuth 2.0 的登录方式,不会在 Home Assistant 中保存您的小米账号密码。但由于 Home Assistant 平台的限制,登录成功后,您的小米用户信息(包括设备信息、证书、 token 等)会明文保存在 Home Assistant 的配置文件中。因此,您需要保管好自己 Home Assistant 配置文件。一旦该文件泄露,其他人可能会冒用您的身份登录。
> 如果您怀疑您的 OAuth 2.0 令牌已泄露,您可以通过以下步骤取消小米账号的登录授权: 米家 APP -> 我的 -> 点击用户名进入小米账号页面 -> 应用授权 -> Xiaomi Home (Home Assistant Integration) -> 取消授权
## 常见问题
- 米家集成是否支持所有的小米米家设备?