Compare commits

...

5 Commits

Author SHA1 Message Date
Necroneco
df9001d688
Merge 506bd9f52e into 75390a3d83 2025-12-18 16:07:52 +08:00
Li Shuzhen
75390a3d83
docs: update changelog and version to v0.4.6 (#1565)
Some checks failed
Tests / check-rule-format (push) Has been cancelled
Validate / validate-hassfest (push) Has been cancelled
Validate / validate-hacs (push) Has been cancelled
Validate / validate-lint (push) Has been cancelled
Validate / validate-setup (push) Has been cancelled
2025-12-18 09:37:27 +08:00
Li Shuzhen
86a739b503
feat: add tv-box device as media player entity (#1562) 2025-12-18 09:04:59 +08:00
caibinqing
506bd9f52e
fix pylint 2025-04-07 11:19:19 +08:00
caibinqing
7c0caa9df7
fix: add migration step for config entry 2025-04-07 10:54:09 +08:00
6 changed files with 197 additions and 19 deletions

View File

@ -1,4 +1,19 @@
# CHANGELOG # CHANGELOG
## v0.4.6
### Added
- Add tv-box device as the media player entity. [#1562](https://github.com/XiaoMi/ha_xiaomi_home/pull/1562)
- Set play-control service's play-loop-mode property as the sound mode. [#1562](https://github.com/XiaoMi/ha_xiaomi_home/pull/1562)
### Changed
- Use constant value to indicate the cloud MQTT broker host domain. [#1530](https://github.com/XiaoMi/ha_xiaomi_home/pull/1530)
- Use constant value to indicate the timer delay of refreshing devices. [#1555](https://github.com/XiaoMi/ha_xiaomi_home/pull/1555)
- Set the playing-state property as the required property in the play-control service of the speaker device. [#1552](https://github.com/XiaoMi/ha_xiaomi_home/pull/1552)
- Set the playing-state property as the required property in the optional play-control service of the television. [#1562](https://github.com/XiaoMi/ha_xiaomi_home/pull/1562)
### Fixed
- Catch paho-mqtt subscribe error properly. [#1551](https://github.com/XiaoMi/ha_xiaomi_home/pull/1551)
- After the network resumes, keep retrying to fetch the device list until it succeeds. [#1555](https://github.com/XiaoMi/ha_xiaomi_home/pull/1555)
- Catch the http post error properly. [#1555](https://github.com/XiaoMi/ha_xiaomi_home/pull/1555)
- Fixed the format and the access field of daikin.aircondition.k2 and fix: daikin.airfresh.k33 string value properties. [#1561](https://github.com/XiaoMi/ha_xiaomi_home/pull/1561)
## v0.4.5 ## v0.4.5
### Changed ### Changed
- Ignore mdns REMOVED package. [#1296](https://github.com/XiaoMi/ha_xiaomi_home/pull/1296) - Ignore mdns REMOVED package. [#1296](https://github.com/XiaoMi/ha_xiaomi_home/pull/1296)

View File

@ -349,3 +349,101 @@ async def async_remove_config_entry_device(
_LOGGER.info( _LOGGER.info(
'remove device, %s, %s', identifiers[1], device_entry.id) 'remove device, %s, %s', identifiers[1], device_entry.id)
return True 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)

View File

@ -109,7 +109,7 @@ _LOGGER = logging.getLogger(__name__)
class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Xiaomi Home config flow.""" """Xiaomi Home config flow."""
# pylint: disable=unused-argument, inconsistent-quotes # pylint: disable=unused-argument, inconsistent-quotes
VERSION = 1 VERSION = 2
MINOR_VERSION = 1 MINOR_VERSION = 1
DEFAULT_AREA_NAME_RULE = 'room' DEFAULT_AREA_NAME_RULE = 'room'
_main_loop: asyncio.AbstractEventLoop _main_loop: asyncio.AbstractEventLoop

View File

@ -25,7 +25,7 @@
"cryptography", "cryptography",
"psutil" "psutil"
], ],
"version": "v0.4.5", "version": "v0.4.6",
"zeroconf": [ "zeroconf": [
"_miot-central._tcp.local." "_miot-central._tcp.local."
] ]

View File

@ -345,6 +345,11 @@ class MIoTDevice:
f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_' f'{ha_domain}.{self._model_strs[0][:9]}_{self.did_tag}_'
f'{self._model_strs[-1][:20]}') 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, def gen_service_entity_id(self, ha_domain: str, siid: int,
description: str) -> str: description: str) -> str:
return ( return (
@ -436,7 +441,8 @@ class MIoTDevice:
optional_properties: dict optional_properties: dict
required_actions: set required_actions: set
optional_actions: set optional_actions: set
# 2. The service shall have all required properties, actions. # 2. The required service shall have all required properties
# and actions.
if service.name in required_services: if service.name in required_services:
required_properties = SPEC_DEVICE_TRANS_MAP[spec_name][ required_properties = SPEC_DEVICE_TRANS_MAP[spec_name][
'required'].get( 'required'].get(
@ -454,6 +460,23 @@ class MIoTDevice:
'required'].get( 'required'].get(
service.name, {} service.name, {}
).get('optional', {}).get('actions', set({})) ).get('optional', {}).get('actions', set({}))
if not {
prop.name for prop in service.properties if prop.access
}.issuperset(set(required_properties.keys())):
return None
if not {
action.name for action in service.actions
}.issuperset(required_actions):
return None
# 3. The required property in required service shall have all
# required access mode.
for prop in service.properties:
if prop.name in required_properties:
if not set(prop.access).issuperset(
required_properties[prop.name]):
return None
# 4. The optional service shall have all required properties
# and actions.
elif service.name in optional_services: elif service.name in optional_services:
required_properties = SPEC_DEVICE_TRANS_MAP[spec_name][ required_properties = SPEC_DEVICE_TRANS_MAP[spec_name][
'optional'].get( 'optional'].get(
@ -471,22 +494,23 @@ class MIoTDevice:
'optional'].get( 'optional'].get(
service.name, {} service.name, {}
).get('optional', {}).get('actions', set({})) ).get('optional', {}).get('actions', set({}))
if not {
prop.name for prop in service.properties if prop.access
}.issuperset(set(required_properties.keys())):
continue
if not {
action.name for action in service.actions
}.issuperset(required_actions):
continue
# 5. The required property in optional service shall have all
# required access mode.
for prop in service.properties:
if prop.name in required_properties:
if not set(prop.access).issuperset(
required_properties[prop.name]):
continue
else: else:
continue continue
if not {
prop.name for prop in service.properties if prop.access
}.issuperset(set(required_properties.keys())):
return None
if not {
action.name for action in service.actions
}.issuperset(required_actions):
return None
# 3. The required property shall have all required access mode.
for prop in service.properties:
if prop.name in required_properties:
if not set(prop.access).issuperset(
required_properties[prop.name]):
return None
# property # property
for prop in service.properties: for prop in service.properties:
if prop.name in set.union( if prop.name in set.union(

View File

@ -331,6 +331,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'actions': {'play'} 'actions': {'play'}
}, },
'optional': { 'optional': {
'properties': {'play-loop-mode'},
'actions': {'pause', 'stop', 'next', 'previous'} 'actions': {'pause', 'stop', 'next', 'previous'}
} }
} }
@ -362,9 +363,49 @@ SPEC_DEVICE_TRANS_MAP: dict = {
}, },
'optional': { 'optional': {
'play-control': { 'play-control': {
'required': {}, 'required': {
'properties': {
'playing-state': {'read'}
}
},
'optional': { 'optional': {
'properties': {'playing-state'}, 'properties': {'play-loop-mode'},
'actions': {'play', 'pause', 'stop', 'next', 'previous'}
}
}
},
'entity': 'television'
},
'tv-box':{
'required': {
'speaker': {
'required': {
'properties': {
'volume': {'read', 'write'}
}
},
'optional': {
'properties': {'mute'}
}
},
'tv-box': {
'required': {
'actions': {'turn-off'}
},
'optional': {
'actions': {'turn-on'}
}
}
},
'optional': {
'play-control': {
'required': {
'properties': {
'playing-state': {'read'}
}
},
'optional': {
'properties': {'play-loop-mode'},
'actions': {'play', 'pause', 'stop', 'next', 'previous'} 'actions': {'play', 'pause', 'stop', 'next', 'previous'}
} }
} }