From 1b87381f432640ae28ae12c8453d528ec2a82e65 Mon Sep 17 00:00:00 2001 From: Li Shuzhen Date: Mon, 24 Nov 2025 17:11:38 +0800 Subject: [PATCH 1/3] Fix specs (#1517) * fix: xiaomi.waterpuri.s1200g filter property unit (#1489) * fix: xiaomi.aircondition.c24 power consumption device class (#1243) * fix: cuco.plug.cp7pd power consumption and power value precision (#1502) * fix: lxzn.valve.02 electricity property unit (#1514) --- .../xiaomi_home/miot/miot_device.py | 1 + .../xiaomi_home/miot/specs/multi_lang.json | 5 ++ .../xiaomi_home/miot/specs/spec_modify.yaml | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/custom_components/xiaomi_home/miot/miot_device.py b/custom_components/xiaomi_home/miot/miot_device.py index 524462a..a0e2edb 100644 --- a/custom_components/xiaomi_home/miot/miot_device.py +++ b/custom_components/xiaomi_home/miot/miot_device.py @@ -748,6 +748,7 @@ class MIoTDevice: 'w': UnitOfPower.WATT, 'W': UnitOfPower.WATT, 'kW': UnitOfPower.KILO_WATT, + 'Wh': UnitOfEnergy.WATT_HOUR, 'kWh': UnitOfEnergy.KILO_WATT_HOUR, 'A': UnitOfElectricCurrent.AMPERE, 'mA': UnitOfElectricCurrent.MILLIAMPERE, diff --git a/custom_components/xiaomi_home/miot/specs/multi_lang.json b/custom_components/xiaomi_home/miot/specs/multi_lang.json index d8204c0..5af6756 100644 --- a/custom_components/xiaomi_home/miot/specs/multi_lang.json +++ b/custom_components/xiaomi_home/miot/specs/multi_lang.json @@ -5,6 +5,11 @@ "service:003:property:001:valuelist:001": "Dry" } }, + "urn:miot-spec-v2:device:electronic-valve:0000A0A7:lxzn-02": { + "zh-Hans": { + "service:004:property:001": "功率过高-阈值设置" + } + }, "urn:miot-spec-v2:device:electronic-valve:0000A0A7:ykcn-cbcs": { "zh-Hans": { "service:004:property:001": "功率过高-阈值设置", diff --git a/custom_components/xiaomi_home/miot/specs/spec_modify.yaml b/custom_components/xiaomi_home/miot/specs/spec_modify.yaml index 4d7a42a..ff5ab33 100644 --- a/custom_components/xiaomi_home/miot/specs/spec_modify.yaml +++ b/custom_components/xiaomi_home/miot/specs/spec_modify.yaml @@ -26,6 +26,7 @@ urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-c20:1: urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-c20:2: urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-c20:1 urn:miot-spec-v2:device:air-conditioner:0000A004:xiaomi-c24:1: prop.8.6: + name: power-consumption unit: kWh prop.10.6: unit: none @@ -144,6 +145,25 @@ urn:miot-spec-v2:device:dehumidifier:0000A02D:xiaomi-lite:1: - -30 - 100 - 0.1 +urn:miot-spec-v2:device:electronic-valve:0000A0A7:lxzn-02:1:0000C833: + prop.3.1: + format: float + value-range: + - 0 + - 999999 + - 0.01 + expr: (src_value/100) + prop.3.2: + unit: mA + prop.3.3: + format: float + value-range: + - 0 + - 65535 + - 0.1 + expr: (src_value/10) + prop.4.1: + unit: kW urn:miot-spec-v2:device:electronic-valve:0000A0A7:sanmei-s1:1: prop.3.1: format: float @@ -370,6 +390,19 @@ urn:miot-spec-v2:device:outlet:0000A002:cuco-cp2:2: urn:miot-spec-v2:device:outlet:0000A002:cuco-cp2d:1: prop.3.2: unit: mA +urn:miot-spec-v2:device:outlet:0000A002:cuco-cp7pd:1: + prop.11.1: + unit: Wh + value-range: + - 0 + - 65535 + - 0.001 + expr: (src_value*1000) + prop.11.4: + value-range: + - 0 + - 10000 + - 0.01 urn:miot-spec-v2:device:outlet:0000A002:cuco-v3:1: prop.11.1: format: float @@ -490,6 +523,24 @@ urn:miot-spec-v2:device:water-purifier:0000A013:roswan-lte01:1:0000D05A: unit: ppm prop.4.2: unit: ppm +urn:miot-spec-v2:device:water-purifier:0000A013:xiaomi-s1200g:1:0000D05A: + prop.3.2: + unit: days + prop.3.3: + unit: days + prop.3.4: + unit: L + prop.3.5: + unit: L + prop.5.2: + unit: days + prop.5.3: + unit: days + prop.5.4: + unit: L + prop.5.5: + unit: L +urn:miot-spec-v2:device:water-purifier:0000A013:xiaomi-s1200g:2:0000D05A: urn:miot-spec-v2:device:water-purifier:0000A013:xiaomi-s1200g:1:0000D05A urn:miot-spec-v2:device:water-purifier:0000A013:yunmi-s20:1: prop.4.1: unit: ppm From e6750bb7467551758d8644d594184098a5456779 Mon Sep 17 00:00:00 2001 From: Li Shuzhen Date: Tue, 25 Nov 2025 09:31:40 +0800 Subject: [PATCH 2/3] feat: format value, then evaluate by expression, and set precision at last (#1516) --- .../xiaomi_home/miot/miot_device.py | 15 +++++++++++---- .../xiaomi_home/miot/miot_spec.py | 18 ++++++++++++++---- custom_components/xiaomi_home/sensor.py | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/custom_components/xiaomi_home/miot/miot_device.py b/custom_components/xiaomi_home/miot/miot_device.py index a0e2edb..a585800 100644 --- a/custom_components/xiaomi_home/miot/miot_device.py +++ b/custom_components/xiaomi_home/miot/miot_device.py @@ -1041,6 +1041,7 @@ class MIoTServiceEntity(Entity): f'set property failed, property is None, ' f'{self.entity_id}, {self.name}') value = prop.value_format(value) + value = prop.value_precision(value) if prop not in self.entity_data.props: raise RuntimeError( f'set property failed, unknown property, ' @@ -1078,9 +1079,11 @@ class MIoTServiceEntity(Entity): 'get property failed, not readable, %s, %s, %s', self.entity_id, self.name, prop.name) return None - result = prop.value_format( + value: Any = prop.value_format( await self.miot_device.miot_client.get_prop_async( did=self.miot_device.did, siid=prop.service.iid, piid=prop.iid)) + value = prop.eval_expr(value) + result = prop.value_precision(value) if result != self._prop_value_map[prop]: self._prop_value_map[prop] = result self.async_write_ha_state() @@ -1111,7 +1114,7 @@ class MIoTServiceEntity(Entity): continue value: Any = prop.value_format(params['value']) value = prop.eval_expr(value) - value = prop.value_format(value) + value = prop.value_precision(value) self._prop_value_map[prop] = value if prop in self._prop_changed_subs: self._prop_changed_subs[prop](prop, value) @@ -1259,6 +1262,7 @@ class MIoTPropertyEntity(Entity): f'set property failed, not writable, ' f'{self.entity_id}, {self.name}') value = self.spec.value_format(value) + value = self.spec.value_precision(value) try: await self.miot_device.miot_client.set_prop_async( did=self.miot_device.did, siid=self.spec.service.iid, @@ -1276,16 +1280,19 @@ class MIoTPropertyEntity(Entity): 'get property failed, not readable, %s, %s', self.entity_id, self.name) return None - return self.spec.value_format( + value: Any = self.spec.value_format( await self.miot_device.miot_client.get_prop_async( did=self.miot_device.did, siid=self.spec.service.iid, piid=self.spec.iid)) + value = self.spec.eval_expr(value) + result = self.spec.value_precision(value) + return result def __on_value_changed(self, params: dict, ctx: Any) -> None: _LOGGER.debug('property changed, %s', params) value: Any = self.spec.value_format(params['value']) value = self.spec.eval_expr(value) - self._value = self.spec.value_format(value) + self._value = self.spec.value_precision(value) if not self._pending_write_ha_state_timer: self.async_write_ha_state() diff --git a/custom_components/xiaomi_home/miot/miot_spec.py b/custom_components/xiaomi_home/miot/miot_spec.py index cd61887..0f7da5e 100644 --- a/custom_components/xiaomi_home/miot/miot_spec.py +++ b/custom_components/xiaomi_home/miot/miot_spec.py @@ -599,15 +599,25 @@ class MIoTSpecProperty(_MIoTSpecBase): def value_format(self, value: Any) -> Any: if value is None: return None + if isinstance(value, str): + if self.format_ == int: + value = int(float(value)) + elif self.format_ == float: + value = float(value) + if self.format_ == bool: + return bool(value in [True, 1, 'True', 'true', '1']) + return value + + def value_precision(self, value: Any) -> Any: + if value is None: + return None + if self.format_ == float: + return round(value, self.precision) if self.format_ == int: if self.value_range is None: return int(round(value)) return int( round(value / self.value_range.step) * self.value_range.step) - if self.format_ == float: - return round(value, self.precision) - if self.format_ == bool: - return bool(value in [True, 1, 'True', 'true', '1']) return value def dump(self) -> dict: diff --git a/custom_components/xiaomi_home/sensor.py b/custom_components/xiaomi_home/sensor.py index 88cb063..02371c9 100644 --- a/custom_components/xiaomi_home/sensor.py +++ b/custom_components/xiaomi_home/sensor.py @@ -110,7 +110,7 @@ class Sensor(MIoTPropertyEntity, SensorEntity): self._attr_native_unit_of_measurement = list( unit_sets)[0] if unit_sets else None # Set suggested precision - if spec.format_ in {int, float} and spec.expr is None: + if spec.format_ == float: self._attr_suggested_display_precision = spec.precision # Set state_class if spec.state_class: From d5c5e387c209c6bcf1b1a80addebe95f6953c2a3 Mon Sep 17 00:00:00 2001 From: Li Shuzhen Date: Tue, 25 Nov 2025 10:04:22 +0800 Subject: [PATCH 3/3] docs: update changelog and version to v0.4.5 (#1521) --- CHANGELOG.md | 8 ++++++++ README.md | 1 + custom_components/xiaomi_home/manifest.json | 2 +- doc/README_zh.md | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19dcf1c..ef3c596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ # CHANGELOG +## v0.4.5 +### Changed +- Ignore mdns REMOVED package. [#1296](https://github.com/XiaoMi/ha_xiaomi_home/pull/1296) +- Format value type first, then evaluate by expression, and set precision at last. [#1516](https://github.com/XiaoMi/ha_xiaomi_home/pull/1516) +### Fixed +- Fix xiaomi.derh.lite temperature precision. [#1505](https://github.com/XiaoMi/ha_xiaomi_home/pull/1505) +- Fix xiaomi.waterpuri.s1200g filter property unit, lxzn.valve.02 electricity property unit, xiaomi.aircondition.c24 power consumption device class, and cuco.plug.cp7pd power consumption and power value precision. [#1517](https://github.com/XiaoMi/ha_xiaomi_home/pull/1517) + ## v0.4.4 ### Added - Add Turkish language support. [#1468](https://github.com/XiaoMi/ha_xiaomi_home/pull/1468) diff --git a/README.md b/README.md index 35fa529..f39615e 100644 --- a/README.md +++ b/README.md @@ -384,6 +384,7 @@ Example: - Contribution Guidelines: [English](./CONTRIBUTING.md) | [简体中文](./doc/CONTRIBUTING_zh.md) - [ChangeLog](./CHANGELOG.md) - Development Documents: https://developers.home-assistant.io/docs/creating_component_index +- [FAQ](https://github.com/XiaoMi/ha_xiaomi_home/wiki) ## Directory Structure diff --git a/custom_components/xiaomi_home/manifest.json b/custom_components/xiaomi_home/manifest.json index b3bd1ba..9632041 100644 --- a/custom_components/xiaomi_home/manifest.json +++ b/custom_components/xiaomi_home/manifest.json @@ -25,7 +25,7 @@ "cryptography", "psutil" ], - "version": "v0.4.4", + "version": "v0.4.5", "zeroconf": [ "_miot-central._tcp.local." ] diff --git a/doc/README_zh.md b/doc/README_zh.md index f0fe035..ab746a2 100644 --- a/doc/README_zh.md +++ b/doc/README_zh.md @@ -386,6 +386,7 @@ siid、piid、eiid、aiid、value 均为十进制三位整数。 - 贡献指南: [English](../CONTRIBUTING.md) | [简体中文](./CONTRIBUTING_zh.md) - [更新日志](../CHANGELOG.md) - 开发文档: https://developers.home-assistant.io/docs/creating_component_index +- [常见问题](https://github.com/XiaoMi/ha_xiaomi_home/wiki) ## 目录结构