Compare commits

..

No commits in common. "main" and "v0.3.0" have entirely different histories.
main ... v0.3.0

9 changed files with 36 additions and 79 deletions

View File

@ -1,12 +1,4 @@
# CHANGELOG
## v0.3.1
### Changed
- Setting the fan speed level when the fan is off will turning the fan on first. [#1031](https://github.com/XiaoMi/ha_xiaomi_home/pull/1031)
### Fixed
- Fix update device list error when there is no shared devices. [#1024](https://github.com/XiaoMi/ha_xiaomi_home/pull/1024)
- Fix the humidifier get_prop_value error when the property is None. [#1035](https://github.com/XiaoMi/ha_xiaomi_home/pull/1035)
- Fix the MIoT-Spec-V2 of zhimi.fan.v3 fan-level, cuco.plug.cp1md voltage and current, zimi.plug.zncz01 electric-power, giot.plug.v8icm power-consumption unit, yunmi.kettle.r3 tds unit, and dmaker.fan.p5 fan-level. [#1037](https://github.com/XiaoMi/ha_xiaomi_home/pull/1037)
## v0.3.0
注意v0.3.0 变更了部分实体 unique_id 的生成规则,如果勾选 xiaomi_home > 配置 > 更新实体转换规则,会导致部分实体已配置的自动化失效。如果想要避免重新配置大量自动化,可使用这个[补丁](https://github.com/XiaoMi/ha_xiaomi_home/pull/972)。
@ -15,6 +7,7 @@ CAUTION: v0.3.0 changes the unique_id of some entities. If you check the option
- Import the devices in the shared homes and the separated shared devices. [#1021](https://github.com/XiaoMi/ha_xiaomi_home/pull/1021)
- Support _attr_hvac_action of the climate entity. [#956](https://github.com/XiaoMi/ha_xiaomi_home/pull/956)
- Add custom defined MIoT-Spec-V2 instance via spec_add.json. [#953](https://github.com/XiaoMi/ha_xiaomi_home/pull/953)
### Fixed
- Ignore 'Event loop is closed' when unsub a closed event loop. [#991](https://github.com/XiaoMi/ha_xiaomi_home/pull/991)
- Fix contact-state for linp.magnet.m1 and loock.safe.v1. [#977](https://github.com/XiaoMi/ha_xiaomi_home/pull/977)

View File

@ -567,8 +567,6 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
# home list
for device_source in ['home_list','share_home_list',
'separated_shared_list']:
if device_source not in self._cc_home_info['homes']:
continue
for home_id, home_info in self._cc_home_info[
'homes'][device_source].items():
# i18n
@ -667,8 +665,6 @@ class XiaomiMihomeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
'no_family_selected')
for device_source in ['home_list','share_home_list',
'separated_shared_list']:
if device_source not in self._cc_home_info['homes']:
continue
for home_id, home_info in self._cc_home_info[
'homes'][device_source].items():
if home_id in home_selected:
@ -1431,8 +1427,6 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
# home list
for device_source in ['home_list','share_home_list',
'separated_shared_list']:
if device_source not in self._cc_home_info['homes']:
continue
for home_id, home_info in self._cc_home_info[
'homes'][device_source].items():
# i18n
@ -1475,8 +1469,6 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
self._home_selected = {}
for device_source in ['home_list','share_home_list',
'separated_shared_list']:
if device_source not in self._cc_home_info['homes']:
continue
for home_id, home_info in self._cc_home_info[
'homes'][device_source].items():
if home_id in self._home_selected_list:

View File

@ -236,9 +236,6 @@ class Fan(MIoTServiceEntity, FanEntity):
async def async_set_percentage(self, percentage: int) -> None:
"""Set the percentage of the fan speed."""
if percentage > 0:
if not self.is_on:
# If the fan is off, turn it on.
await self.set_property_async(prop=self._prop_on, value=True)
if self._speed_names:
await self.set_property_async(
prop=self._prop_fan_level,
@ -252,6 +249,9 @@ class Fan(MIoTServiceEntity, FanEntity):
value=int(percentage_to_ranged_value(
low_high_range=(self._speed_min, self._speed_max),
percentage=percentage)))
if not self.is_on:
# If the fan is off, turn it on.
await self.set_property_async(prop=self._prop_on, value=True)
else:
await self.set_property_async(prop=self._prop_on, value=False)

View File

@ -52,22 +52,23 @@ from typing import Any, Optional
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.humidifier import (HumidifierEntity,
HumidifierDeviceClass,
HumidifierEntityFeature,
HumidifierAction)
from homeassistant.components.humidifier import (
HumidifierEntity,
HumidifierDeviceClass,
HumidifierEntityFeature
)
from .miot.miot_spec import MIoTSpecProperty
from .miot.miot_device import MIoTDevice, MIoTEntityData, MIoTServiceEntity
from .miot.miot_device import MIoTDevice, MIoTEntityData, MIoTServiceEntity
from .miot.const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up a config entry."""
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
@ -81,8 +82,8 @@ async def async_setup_entry(
Humidifier(miot_device=miot_device, entity_data=data))
for data in miot_device.entity_list.get('dehumidifier', []):
data.device_class = HumidifierDeviceClass.DEHUMIDIFIER
new_entities.append(
Humidifier(miot_device=miot_device, entity_data=data))
new_entities.append(Humidifier(
miot_device=miot_device, entity_data=data))
if new_entities:
async_add_entities(new_entities)
@ -98,8 +99,9 @@ class Humidifier(MIoTServiceEntity, HumidifierEntity):
_mode_map: dict[Any, Any]
def __init__(self, miot_device: MIoTDevice,
entity_data: MIoTEntityData) -> None:
def __init__(
self, miot_device: MIoTDevice, entity_data: MIoTEntityData
) -> None:
"""Initialize the Humidifier."""
super().__init__(miot_device=miot_device, entity_data=entity_data)
self._attr_device_class = entity_data.device_class
@ -128,10 +130,12 @@ class Humidifier(MIoTServiceEntity, HumidifierEntity):
# mode
elif prop.name == 'mode':
if not prop.value_list:
_LOGGER.error('mode value_list is None, %s', self.entity_id)
_LOGGER.error(
'mode value_list is None, %s', self.entity_id)
continue
self._mode_map = prop.value_list.to_map()
self._attr_available_modes = list(self._mode_map.values())
self._attr_available_modes = list(
self._mode_map.values())
self._attr_supported_features |= HumidifierEntityFeature.MODES
self._prop_mode = prop
# relative-humidity
@ -148,45 +152,33 @@ class Humidifier(MIoTServiceEntity, HumidifierEntity):
async def async_set_humidity(self, humidity: int) -> None:
"""Set new target humidity."""
if self._prop_target_humidity is None:
return
await self.set_property_async(prop=self._prop_target_humidity,
value=humidity)
await self.set_property_async(
prop=self._prop_target_humidity, value=humidity)
async def async_set_mode(self, mode: str) -> None:
"""Set new target preset mode."""
await self.set_property_async(prop=self._prop_mode,
value=self.get_map_key(
map_=self._mode_map, value=mode))
await self.set_property_async(
prop=self._prop_mode,
value=self.get_map_key(map_=self._mode_map, value=mode))
@property
def is_on(self) -> Optional[bool]:
"""Return if the humidifier is on."""
return self.get_prop_value(prop=self._prop_on)
@property
def action(self) -> Optional[HumidifierAction]:
"""Return the current status of the device."""
if not self.is_on:
return HumidifierAction.OFF
if self._attr_device_class == HumidifierDeviceClass.HUMIDIFIER:
return HumidifierAction.HUMIDIFYING
return HumidifierAction.DRYING
@property
def current_humidity(self) -> Optional[int]:
"""Return the current humidity."""
return (self.get_prop_value(
prop=self._prop_humidity) if self._prop_humidity else None)
return self.get_prop_value(prop=self._prop_humidity)
@property
def target_humidity(self) -> Optional[int]:
"""Return the target humidity."""
return (self.get_prop_value(prop=self._prop_target_humidity)
if self._prop_target_humidity else None)
return self.get_prop_value(prop=self._prop_target_humidity)
@property
def mode(self) -> Optional[str]:
"""Return the current preset mode."""
return self.get_map_value(map_=self._mode_map,
key=self.get_prop_value(prop=self._prop_mode))
return self.get_map_value(
map_=self._mode_map,
key=self.get_prop_value(prop=self._prop_mode))

View File

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

View File

@ -779,10 +779,8 @@ class MIoTDevice:
# pylint: disable=import-outside-toplevel
from homeassistant.const import UnitOfConductivity # type: ignore
unit_map['μS/cm'] = UnitOfConductivity.MICROSIEMENS_PER_CM
unit_map['mWh'] = UnitOfEnergy.MILLIWATT_HOUR
except Exception: # pylint: disable=broad-except
unit_map['μS/cm'] = 'μS/cm'
unit_map['mWh'] = 'mWh'
return unit_map.get(spec_unit, None)

View File

@ -47,15 +47,9 @@ urn:miot-spec-v2:device:bath-heater:0000A028:opple-acmoto:1:
urn:miot-spec-v2:device:bath-heater:0000A028:xiaomi-s1:1:
prop.4.4:
name: fan-level-ventilation
urn:miot-spec-v2:device:fan:0000A005:dmaker-p5:1:
prop.2.6:
name: fan-level-a
urn:miot-spec-v2:device:fan:0000A005:xiaomi-p51:1:
prop.2.2:
name: fan-level-a
urn:miot-spec-v2:device:fan:0000A005:zhimi-v3:3:
prop.2.6:
name: fan-level-a
urn:miot-spec-v2:device:gateway:0000A019:lumi-mcn001:1:
prop.2.1:
access:
@ -87,13 +81,10 @@ urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1:1:
- notify
urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1:2: urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1:1
urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1:3: urn:miot-spec-v2:device:gateway:0000A019:xiaomi-hub1:1
urn:miot-spec-v2:device:kettle:0000A009:yunmi-r3:1:
prop.3.1:
unit: ppm
urn:miot-spec-v2:device:light:0000A001:shhf-sfla12:1:
prop.8.11:
name: on-a
urn:miot-spec-v2:device:magnet-sensor:0000A016:linp-m1:1:
urn:miot-spec-v2:device:magnet-sensor:0000A016:linp-m1:1: # linp.magnet.m1
prop.2.1004:
name: contact-state
expr: src_value!=1
@ -118,10 +109,6 @@ urn:miot-spec-v2:device:outlet:0000A002:cuco-cp1md:1:
prop.2.2:
name: power-consumption
expr: round(src_value/1000, 3)
prop.2.3:
expr: round(src_value/10, 1)
prop.2.4:
unit: mA
urn:miot-spec-v2:device:outlet:0000A002:cuco-cp2:1: urn:miot-spec-v2:device:outlet:0000A002:cuco-cp2:2
urn:miot-spec-v2:device:outlet:0000A002:cuco-cp2:2:
prop.2.3:
@ -135,15 +122,11 @@ urn:miot-spec-v2:device:outlet:0000A002:cuco-v3:1:
name: power-consumption
expr: round(src_value/100, 2)
urn:miot-spec-v2:device:outlet:0000A002:cuco-v3:2: urn:miot-spec-v2:device:outlet:0000A002:cuco-v3:1
urn:miot-spec-v2:device:outlet:0000A002:giot-v8icm:1:0000C816:
prop.4.1:
unit: mWh
urn:miot-spec-v2:device:outlet:0000A002:qmi-psv3:1:0000C816:
prop.3.3:
unit: mV
prop.3.4:
unit: mA
urn:miot-spec-v2:device:outlet:0000A002:zimi-zncz01:1:0000C816: urn:miot-spec-v2:device:outlet:0000A002:zimi-zncz01:2:0000C816
urn:miot-spec-v2:device:outlet:0000A002:zimi-zncz01:2:0000C816:
prop.3.1:
name: electric-power
@ -168,7 +151,7 @@ urn:miot-spec-v2:device:router:0000A036:xiaomi-rd08:1:
name: upload-speed
icon: mdi:upload
unit: B/s
urn:miot-spec-v2:device:safe-box:0000A042:loock-v1:1:
urn:miot-spec-v2:device:safe-box:0000A042:loock-v1:1: # loock.safe.v1
prop.5.1:
name: contact-state
expr: src_value!=1

View File

@ -389,7 +389,6 @@ SPEC_SERVICE_TRANS_MAP: dict = {
'fan-control': 'fan',
'ceiling-fan': 'fan',
'air-fresh': 'fan',
'air-purifier': 'fan',
'water-heater': {
'required': {
'properties': {

View File

@ -38,7 +38,7 @@ def load_json_file(file_path: str) -> Optional[dict]:
def save_json_file(file_path: str, data: dict) -> None:
with open(file_path, 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=2)
json.dump(data, file, ensure_ascii=False, indent=4)
def load_yaml_file(file_path: str) -> Optional[dict]: