mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 15:41:15 +08:00
Compare commits
4 Commits
e6dcd4b1c8
...
8344548872
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8344548872 | ||
|
|
a11c3e2fda | ||
|
|
506bd9f52e | ||
|
|
7c0caa9df7 |
@ -349,3 +349,101 @@ async def async_remove_config_entry_device(
|
||||
_LOGGER.info(
|
||||
'remove device, %s, %s', identifiers[1], device_entry.id)
|
||||
return True
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
"""Migrate old entry."""
|
||||
_LOGGER.debug(
|
||||
'Migrating configuration from version %s.%s',
|
||||
config_entry.version,
|
||||
config_entry.minor_version,
|
||||
)
|
||||
|
||||
if config_entry.version > 1:
|
||||
# This means the user has downgraded from a future version
|
||||
return False
|
||||
|
||||
if config_entry.version == 1:
|
||||
await _migrate_v1_to_v2(hass, config_entry)
|
||||
|
||||
_LOGGER.debug(
|
||||
'Migration to configuration version %s.%s successful',
|
||||
config_entry.version,
|
||||
config_entry.minor_version,
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def _migrate_v1_to_v2(hass: HomeAssistant, config_entry: ConfigEntry):
|
||||
def ha_persistent_notify(
|
||||
notify_id: str, title: Optional[str] = None,
|
||||
message: Optional[str] = None
|
||||
) -> None:
|
||||
"""Send messages in Notifications dialog box."""
|
||||
if title:
|
||||
persistent_notification.async_create(
|
||||
hass=hass, message=message or '',
|
||||
title=title, notification_id=notify_id)
|
||||
else:
|
||||
persistent_notification.async_dismiss(
|
||||
hass=hass, notification_id=notify_id)
|
||||
|
||||
entry_id = config_entry.entry_id
|
||||
entry_data = dict(config_entry.data)
|
||||
|
||||
ha_persistent_notify(
|
||||
notify_id=f'{entry_id}.oauth_error', title=None, message=None)
|
||||
|
||||
miot_client: MIoTClient = await get_miot_instance_async(
|
||||
hass=hass, entry_id=entry_id,
|
||||
entry_data=entry_data,
|
||||
persistent_notify=ha_persistent_notify)
|
||||
# Spec parser
|
||||
spec_parser = MIoTSpecParser(
|
||||
lang=entry_data.get(
|
||||
'integration_language', DEFAULT_INTEGRATION_LANGUAGE),
|
||||
storage=miot_client.miot_storage,
|
||||
loop=miot_client.main_loop
|
||||
)
|
||||
await spec_parser.init_async()
|
||||
# Manufacturer
|
||||
manufacturer: DeviceManufacturer = DeviceManufacturer(
|
||||
storage=miot_client.miot_storage,
|
||||
loop=miot_client.main_loop)
|
||||
await manufacturer.init_async()
|
||||
er = entity_registry.async_get(hass)
|
||||
for _, info in miot_client.device_list.items():
|
||||
spec_instance = await spec_parser.parse(urn=info['urn'])
|
||||
if not isinstance(spec_instance, MIoTSpecInstance):
|
||||
continue
|
||||
device: MIoTDevice = MIoTDevice(
|
||||
miot_client=miot_client,
|
||||
device_info={
|
||||
**info, 'manufacturer': manufacturer.get_name(
|
||||
info.get('manufacturer', ''))},
|
||||
spec_instance=spec_instance)
|
||||
device.spec_transform()
|
||||
|
||||
# Update unique_id
|
||||
for platform, entities in device.entity_list.items():
|
||||
for entity in entities:
|
||||
if not isinstance(entity.spec, MIoTSpecService):
|
||||
continue
|
||||
old_unique_id = device.gen_service_entity_id_v1(
|
||||
ha_domain=DOMAIN,
|
||||
siid=entity.spec.iid,
|
||||
)
|
||||
entity_id = er.async_get_entity_id(
|
||||
platform, DOMAIN, old_unique_id
|
||||
)
|
||||
if entity_id is None:
|
||||
continue
|
||||
new_unique_id = device.gen_service_entity_id(
|
||||
ha_domain=DOMAIN,
|
||||
siid=entity.spec.iid,
|
||||
description=entity.spec.description,
|
||||
)
|
||||
er.async_update_entity(entity_id, new_unique_id=new_unique_id)
|
||||
|
||||
hass.config_entries.async_update_entry(config_entry, version=2)
|
||||
|
||||
@ -108,7 +108,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Xiaomi Home config flow."""
|
||||
# pylint: disable=unused-argument, inconsistent-quotes
|
||||
VERSION = 1
|
||||
VERSION = 2
|
||||
MINOR_VERSION = 1
|
||||
DEFAULT_AREA_NAME_RULE = 'room'
|
||||
_main_loop: asyncio.AbstractEventLoop
|
||||
|
||||
@ -345,6 +345,11 @@ class MIoTDevice:
|
||||
f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_'
|
||||
f'{self._model_strs[-1][:20]}')
|
||||
|
||||
def gen_service_entity_id_v1(self, ha_domain: str, siid: int) -> str:
|
||||
return (
|
||||
f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_'
|
||||
f'{self._model_strs[-1][:20]}_s_{siid}')
|
||||
|
||||
def gen_service_entity_id(self, ha_domain: str, siid: int,
|
||||
description: str) -> str:
|
||||
return (
|
||||
|
||||
@ -5,6 +5,12 @@
|
||||
"service:003:property:001:valuelist:001": "Dry"
|
||||
}
|
||||
},
|
||||
"urn:miot-spec-v2:device:fan:0000A005:zhimi-za1": {
|
||||
"zh-Hans": {
|
||||
"service:002:property:005:valuelist:000": "自然风",
|
||||
"service:002:property:005:valuelist:001": "直吹风"
|
||||
}
|
||||
},
|
||||
"urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1": {
|
||||
"de": {
|
||||
"service:001": "Geräteinformationen",
|
||||
@ -274,13 +280,13 @@
|
||||
"service:002:property:002": "Air Conditioner Mode",
|
||||
"service:004": "Air Conditioner"
|
||||
},
|
||||
"zh_cn": {
|
||||
"zh-Hans": {
|
||||
"service:002": "地暖",
|
||||
"service:004": "空调"
|
||||
}
|
||||
},
|
||||
"urn:miot-spec-v2:device:vacuum:0000A006:ijai-v1": {
|
||||
"zh_cn": {
|
||||
"zh-Hans": {
|
||||
"service:007:property:005:valuelist:000": "安静",
|
||||
"service:007:property:005:valuelist:001": "标准",
|
||||
"service:007:property:005:valuelist:002": "中档",
|
||||
|
||||
@ -82,6 +82,22 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"urn:miot-spec-v2:device:speaker:0000A015:xiaomi-l05b:1": [
|
||||
{
|
||||
"iid": 3,
|
||||
"type": "urn:miot-spec-v2:service:play:0000781D:xiaomi-l05b:1",
|
||||
"description": "Play Control",
|
||||
"actions": [
|
||||
{
|
||||
"iid": 2,
|
||||
"type": "urn:miot-spec-v2:action:play:0000280B:xiaomi-l05b:1",
|
||||
"description": "Play",
|
||||
"in": [],
|
||||
"out": []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"urn:miot-spec-v2:device:thermostat:0000A031:tofan-wk01:1:0000C822": [
|
||||
{
|
||||
"iid": 2,
|
||||
@ -1660,6 +1676,24 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"urn:miot-spec-v2:device:vacuum:0000A006:roidmi-v60:3": [
|
||||
{
|
||||
"iid": 2,
|
||||
"type": "urn:miot-spec-v2:service:vacuum:00007810:roidmi-v60:1",
|
||||
"description": "Robot Cleaner",
|
||||
"actions": [
|
||||
{
|
||||
"iid": 3,
|
||||
"type": "urn:miot-spec-v2:action:start-room-sweep:00002826:roidmi-v60:1",
|
||||
"description": "Start Room Sweep",
|
||||
"in": [
|
||||
9
|
||||
],
|
||||
"out": []
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"urn:miot-spec-v2:device:water-heater:0000A02A:viomi-m1:2": [
|
||||
{
|
||||
"iid": 2,
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
urn:miot-spec-v2:device:air-conditioner:0000A004:090615-ktf:
|
||||
services:
|
||||
- '4'
|
||||
urn:miot-spec-v2:device:air-conditioner:0000A004:759413-iez:
|
||||
properties:
|
||||
- '2.3'
|
||||
urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-ma4:
|
||||
properties:
|
||||
- 9.*
|
||||
@ -44,6 +47,13 @@ urn:miot-spec-v2:device:motion-sensor:0000A014:xiaomi-pir1:
|
||||
services:
|
||||
- '1'
|
||||
- '5'
|
||||
urn:miot-spec-v2:device:speaker:0000A015:xiaomi-l15a:
|
||||
properties:
|
||||
- '3.3'
|
||||
- '6.1'
|
||||
- '6.2'
|
||||
- '6.3'
|
||||
- '6.4'
|
||||
urn:miot-spec-v2:device:thermostat:0000A031:tofan-wk01:
|
||||
services:
|
||||
- '2'
|
||||
@ -54,3 +64,6 @@ urn:miot-spec-v2:device:vacuum:0000A006:narwa-001:
|
||||
urn:miot-spec-v2:device:vacuum:0000A006:narwa-ax11:
|
||||
services:
|
||||
- '*'
|
||||
urn:miot-spec-v2:device:vacuum:0000A006:roidmi-v60:
|
||||
actions:
|
||||
- '2.3'
|
||||
|
||||
@ -48,6 +48,18 @@ urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-mt0:2: urn:miot-spec-v2:
|
||||
urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:1:
|
||||
prop.10.6:
|
||||
unit: none
|
||||
prop.3.12:
|
||||
name: vertical-swing-left-up
|
||||
prop.3.13:
|
||||
name: vertical-swing-left-down
|
||||
prop.3.14:
|
||||
name: vertical-swing-right-up
|
||||
prop.3.15:
|
||||
name: vertical-swing-right-down
|
||||
prop.3.20:
|
||||
name: horizontal-swing-left
|
||||
prop.3.22:
|
||||
name: horizontal-swing-right
|
||||
urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:2: urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:1
|
||||
urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:3: urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:1
|
||||
urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:4: urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-rr0r00:1
|
||||
@ -72,6 +84,8 @@ urn:miot-spec-v2:device:airer:0000A00D:hyd-lyjpro:1:
|
||||
name: target-position-a
|
||||
prop.2.9:
|
||||
name: target-position-b
|
||||
prop.2.11:
|
||||
expr: (100-src_value)
|
||||
urn:miot-spec-v2:device:airer:0000A00D:hyd-znlyj5:1:
|
||||
prop.2.3:
|
||||
value-range:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user