mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2025-12-14 02:00:34 +08:00
Compare commits
2 Commits
1b87381f43
...
d5c5e387c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5c5e387c2 | ||
|
|
e6750bb746 |
@ -1,4 +1,12 @@
|
|||||||
# CHANGELOG
|
# 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
|
## v0.4.4
|
||||||
### Added
|
### Added
|
||||||
- Add Turkish language support. [#1468](https://github.com/XiaoMi/ha_xiaomi_home/pull/1468)
|
- Add Turkish language support. [#1468](https://github.com/XiaoMi/ha_xiaomi_home/pull/1468)
|
||||||
|
|||||||
@ -384,6 +384,7 @@ Example:
|
|||||||
- Contribution Guidelines: [English](./CONTRIBUTING.md) | [简体中文](./doc/CONTRIBUTING_zh.md)
|
- Contribution Guidelines: [English](./CONTRIBUTING.md) | [简体中文](./doc/CONTRIBUTING_zh.md)
|
||||||
- [ChangeLog](./CHANGELOG.md)
|
- [ChangeLog](./CHANGELOG.md)
|
||||||
- Development Documents: https://developers.home-assistant.io/docs/creating_component_index
|
- Development Documents: https://developers.home-assistant.io/docs/creating_component_index
|
||||||
|
- [FAQ](https://github.com/XiaoMi/ha_xiaomi_home/wiki)
|
||||||
|
|
||||||
## Directory Structure
|
## Directory Structure
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
"cryptography",
|
"cryptography",
|
||||||
"psutil"
|
"psutil"
|
||||||
],
|
],
|
||||||
"version": "v0.4.4",
|
"version": "v0.4.5",
|
||||||
"zeroconf": [
|
"zeroconf": [
|
||||||
"_miot-central._tcp.local."
|
"_miot-central._tcp.local."
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1041,6 +1041,7 @@ class MIoTServiceEntity(Entity):
|
|||||||
f'set property failed, property is None, '
|
f'set property failed, property is None, '
|
||||||
f'{self.entity_id}, {self.name}')
|
f'{self.entity_id}, {self.name}')
|
||||||
value = prop.value_format(value)
|
value = prop.value_format(value)
|
||||||
|
value = prop.value_precision(value)
|
||||||
if prop not in self.entity_data.props:
|
if prop not in self.entity_data.props:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f'set property failed, unknown property, '
|
f'set property failed, unknown property, '
|
||||||
@ -1078,9 +1079,11 @@ class MIoTServiceEntity(Entity):
|
|||||||
'get property failed, not readable, %s, %s, %s',
|
'get property failed, not readable, %s, %s, %s',
|
||||||
self.entity_id, self.name, prop.name)
|
self.entity_id, self.name, prop.name)
|
||||||
return None
|
return None
|
||||||
result = prop.value_format(
|
value: Any = prop.value_format(
|
||||||
await self.miot_device.miot_client.get_prop_async(
|
await self.miot_device.miot_client.get_prop_async(
|
||||||
did=self.miot_device.did, siid=prop.service.iid, piid=prop.iid))
|
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]:
|
if result != self._prop_value_map[prop]:
|
||||||
self._prop_value_map[prop] = result
|
self._prop_value_map[prop] = result
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
@ -1111,7 +1114,7 @@ class MIoTServiceEntity(Entity):
|
|||||||
continue
|
continue
|
||||||
value: Any = prop.value_format(params['value'])
|
value: Any = prop.value_format(params['value'])
|
||||||
value = prop.eval_expr(value)
|
value = prop.eval_expr(value)
|
||||||
value = prop.value_format(value)
|
value = prop.value_precision(value)
|
||||||
self._prop_value_map[prop] = value
|
self._prop_value_map[prop] = value
|
||||||
if prop in self._prop_changed_subs:
|
if prop in self._prop_changed_subs:
|
||||||
self._prop_changed_subs[prop](prop, value)
|
self._prop_changed_subs[prop](prop, value)
|
||||||
@ -1259,6 +1262,7 @@ class MIoTPropertyEntity(Entity):
|
|||||||
f'set property failed, not writable, '
|
f'set property failed, not writable, '
|
||||||
f'{self.entity_id}, {self.name}')
|
f'{self.entity_id}, {self.name}')
|
||||||
value = self.spec.value_format(value)
|
value = self.spec.value_format(value)
|
||||||
|
value = self.spec.value_precision(value)
|
||||||
try:
|
try:
|
||||||
await self.miot_device.miot_client.set_prop_async(
|
await self.miot_device.miot_client.set_prop_async(
|
||||||
did=self.miot_device.did, siid=self.spec.service.iid,
|
did=self.miot_device.did, siid=self.spec.service.iid,
|
||||||
@ -1276,16 +1280,19 @@ class MIoTPropertyEntity(Entity):
|
|||||||
'get property failed, not readable, %s, %s',
|
'get property failed, not readable, %s, %s',
|
||||||
self.entity_id, self.name)
|
self.entity_id, self.name)
|
||||||
return None
|
return None
|
||||||
return self.spec.value_format(
|
value: Any = self.spec.value_format(
|
||||||
await self.miot_device.miot_client.get_prop_async(
|
await self.miot_device.miot_client.get_prop_async(
|
||||||
did=self.miot_device.did, siid=self.spec.service.iid,
|
did=self.miot_device.did, siid=self.spec.service.iid,
|
||||||
piid=self.spec.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:
|
def __on_value_changed(self, params: dict, ctx: Any) -> None:
|
||||||
_LOGGER.debug('property changed, %s', params)
|
_LOGGER.debug('property changed, %s', params)
|
||||||
value: Any = self.spec.value_format(params['value'])
|
value: Any = self.spec.value_format(params['value'])
|
||||||
value = self.spec.eval_expr(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:
|
if not self._pending_write_ha_state_timer:
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
|||||||
@ -599,15 +599,25 @@ class MIoTSpecProperty(_MIoTSpecBase):
|
|||||||
def value_format(self, value: Any) -> Any:
|
def value_format(self, value: Any) -> Any:
|
||||||
if value is None:
|
if value is None:
|
||||||
return 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.format_ == int:
|
||||||
if self.value_range is None:
|
if self.value_range is None:
|
||||||
return int(round(value))
|
return int(round(value))
|
||||||
return int(
|
return int(
|
||||||
round(value / self.value_range.step) * self.value_range.step)
|
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
|
return value
|
||||||
|
|
||||||
def dump(self) -> dict:
|
def dump(self) -> dict:
|
||||||
|
|||||||
@ -110,7 +110,7 @@ class Sensor(MIoTPropertyEntity, SensorEntity):
|
|||||||
self._attr_native_unit_of_measurement = list(
|
self._attr_native_unit_of_measurement = list(
|
||||||
unit_sets)[0] if unit_sets else None
|
unit_sets)[0] if unit_sets else None
|
||||||
# Set suggested precision
|
# 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
|
self._attr_suggested_display_precision = spec.precision
|
||||||
# Set state_class
|
# Set state_class
|
||||||
if spec.state_class:
|
if spec.state_class:
|
||||||
|
|||||||
@ -386,6 +386,7 @@ siid、piid、eiid、aiid、value 均为十进制三位整数。
|
|||||||
- 贡献指南: [English](../CONTRIBUTING.md) | [简体中文](./CONTRIBUTING_zh.md)
|
- 贡献指南: [English](../CONTRIBUTING.md) | [简体中文](./CONTRIBUTING_zh.md)
|
||||||
- [更新日志](../CHANGELOG.md)
|
- [更新日志](../CHANGELOG.md)
|
||||||
- 开发文档: https://developers.home-assistant.io/docs/creating_component_index
|
- 开发文档: https://developers.home-assistant.io/docs/creating_component_index
|
||||||
|
- [常见问题](https://github.com/XiaoMi/ha_xiaomi_home/wiki)
|
||||||
|
|
||||||
## 目录结构
|
## 目录结构
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user