Compare commits

..

1 Commits

Author SHA1 Message Date
Li Shuzhen
1b11b2bc40
Merge 84e79c3435 into 6557b22a52 2025-01-10 09:26:33 +08:00
3 changed files with 34 additions and 54 deletions

View File

@ -1,16 +1,5 @@
# CHANGELOG # CHANGELOG
## v0.1.5b1
This version will cause some Xiaomi routers that do not support access (#564) to become unavailable. You can update the device list in the configuration or delete it manually.
### Added
- Fan entity support direction ctrl [#556](https://github.com/XiaoMi/ha_xiaomi_home/pull/556)
### Changed
- Filter miwifi.* devices and xiaomi.router.rd03 [#564](https://github.com/XiaoMi/ha_xiaomi_home/pull/564)
### Fixed
- Fix multi ha instance login [#560](https://github.com/XiaoMi/ha_xiaomi_home/pull/560)
- Fix fan speed [#464](https://github.com/XiaoMi/ha_xiaomi_home/pull/464)
- The number of profile models updated from 660 to 823. [#583](https://github.com/XiaoMi/ha_xiaomi_home/pull/583)
## v0.1.5b0 ## v0.1.5b0
### Added ### Added
- Add missing parameter state_class [#101](https://github.com/XiaoMi/ha_xiaomi_home/pull/101) - Add missing parameter state_class [#101](https://github.com/XiaoMi/ha_xiaomi_home/pull/101)

View File

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

View File

@ -57,32 +57,30 @@ from homeassistant.components.water_heater import (
STATE_OFF, STATE_OFF,
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
WaterHeaterEntity, WaterHeaterEntity,
WaterHeaterEntityFeature, WaterHeaterEntityFeature
) )
from .miot.const import DOMAIN from .miot.const import DOMAIN
from .miot.miot_device import MIoTDevice, MIoTEntityData, MIoTServiceEntity from .miot.miot_device import MIoTDevice, MIoTEntityData, MIoTServiceEntity
from .miot.miot_spec import MIoTSpecProperty from .miot.miot_spec import MIoTSpecProperty
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, hass: HomeAssistant,
config_entry: ConfigEntry, config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
) -> None: ) -> None:
"""Set up a config entry.""" """Set up a config entry."""
device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][ device_list: list[MIoTDevice] = hass.data[DOMAIN]['devices'][
config_entry.entry_id config_entry.entry_id]
]
new_entities = [] new_entities = []
for miot_device in device_list: for miot_device in device_list:
for data in miot_device.entity_list.get('water_heater', []): for data in miot_device.entity_list.get('water_heater', []):
new_entities.append( new_entities.append(WaterHeater(
WaterHeater(miot_device=miot_device, entity_data=data) miot_device=miot_device, entity_data=data))
)
if new_entities: if new_entities:
async_add_entities(new_entities) async_add_entities(new_entities)
@ -90,11 +88,11 @@ async def async_setup_entry(
class WaterHeater(MIoTServiceEntity, WaterHeaterEntity): class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
"""Water heater entities for Xiaomi Home.""" """Water heater entities for Xiaomi Home."""
_prop_on: Optional[MIoTSpecProperty] _prop_on: Optional[MIoTSpecProperty]
_prop_temp: Optional[MIoTSpecProperty] _prop_temp: Optional[MIoTSpecProperty]
_prop_target_temp: Optional[MIoTSpecProperty] _prop_target_temp: Optional[MIoTSpecProperty]
_prop_mode: Optional[MIoTSpecProperty] _prop_mode: Optional[MIoTSpecProperty]
_mode_map: Optional[dict[int, str]] _mode_map: Optional[dict[int, str]]
def __init__( def __init__(
@ -108,14 +106,15 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
self._prop_temp = None self._prop_temp = None
self._prop_target_temp = None self._prop_target_temp = None
self._prop_mode = None self._prop_mode = None
self._mode_map = None self._mode_list = None
# properties # properties
for prop in entity_data.props: for prop in entity_data.props:
# on # on
if prop.name == 'on': if prop.name == 'on':
self._prop_on = prop self._prop_on = prop
self._attr_supported_features |= WaterHeaterEntityFeature.ON_OFF self._attr_supported_features |= (
WaterHeaterEntityFeature.ON_OFF)
# temperature # temperature
if prop.name == 'temperature': if prop.name == 'temperature':
if isinstance(prop.value_range, dict): if isinstance(prop.value_range, dict):
@ -128,8 +127,7 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
else: else:
_LOGGER.error( _LOGGER.error(
'invalid temperature value_range format, %s', 'invalid temperature value_range format, %s',
self.entity_id, self.entity_id)
)
# target-temperature # target-temperature
if prop.name == 'target-temperature': if prop.name == 'target-temperature':
self._attr_min_temp = prop.value_range['min'] self._attr_min_temp = prop.value_range['min']
@ -138,22 +136,23 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
if self._attr_temperature_unit is None and prop.external_unit: if self._attr_temperature_unit is None and prop.external_unit:
self._attr_temperature_unit = prop.external_unit self._attr_temperature_unit = prop.external_unit
self._attr_supported_features |= ( self._attr_supported_features |= (
WaterHeaterEntityFeature.TARGET_TEMPERATURE WaterHeaterEntityFeature.TARGET_TEMPERATURE)
)
self._prop_target_temp = prop self._prop_target_temp = prop
# mode # mode
if prop.name == 'mode': if prop.name == 'mode':
if not isinstance(prop.value_list, list) or not prop.value_list: if (
_LOGGER.error('mode value_list is None, %s', self.entity_id) not isinstance(prop.value_list, list)
or not prop.value_list
):
_LOGGER.error(
'mode value_list is None, %s', self.entity_id)
continue continue
self._mode_map = { self._mode_map = {
item['value']: item['description'] item['value']: item['description']
for item in prop.value_list for item in prop.value_list}
}
self._attr_operation_list = list(self._mode_map.values()) self._attr_operation_list = list(self._mode_map.values())
self._attr_supported_features |= ( self._attr_supported_features |= (
WaterHeaterEntityFeature.OPERATION_MODE WaterHeaterEntityFeature.OPERATION_MODE)
)
self._prop_mode = prop self._prop_mode = prop
if not self._attr_operation_list: if not self._attr_operation_list:
self._attr_operation_list = [STATE_ON] self._attr_operation_list = [STATE_ON]
@ -170,8 +169,7 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
async def async_set_temperature(self, **kwargs: Any) -> None: async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set the temperature the water heater should heat water to.""" """Set the temperature the water heater should heat water to."""
await self.set_property_async( await self.set_property_async(
prop=self._prop_target_temp, value=kwargs[ATTR_TEMPERATURE] prop=self._prop_target_temp, value=kwargs[ATTR_TEMPERATURE])
)
async def async_set_operation_mode(self, operation_mode: str) -> None: async def async_set_operation_mode(self, operation_mode: str) -> None:
"""Set the operation mode of the water heater. """Set the operation mode of the water heater.
@ -184,31 +182,26 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
await self.set_property_async(prop=self._prop_on, value=True) await self.set_property_async(prop=self._prop_on, value=True)
return return
if self.get_prop_value(prop=self._prop_on) is False: if self.get_prop_value(prop=self._prop_on) is False:
await self.set_property_async(prop=self._prop_on, value=True) await self.set_property_async(
prop=self._prop_on, value=True, update=False)
await self.set_property_async( await self.set_property_async(
prop=self._prop_mode, prop=self._prop_mode,
value=self.get_map_value( value=self.get_map_value(
map_=self._mode_map, description=operation_mode map_=self._mode_map, description=operation_mode))
),
) async def async_turn_away_mode_on(self) -> None:
"""Set the water heater to away mode."""
await self.hass.async_add_executor_job(self.turn_away_mode_on)
@property @property
def current_temperature(self) -> Optional[float]: def current_temperature(self) -> Optional[float]:
"""Return the current temperature.""" """Return the current temperature."""
return ( return self.get_prop_value(prop=self._prop_temp)
self.get_prop_value(prop=self._prop_temp)
if self._prop_temp
else None
)
@property @property
def target_temperature(self) -> Optional[float]: def target_temperature(self) -> Optional[float]:
"""Return the target temperature.""" """Return the target temperature."""
return ( return self.get_prop_value(prop=self._prop_target_temp)
self.get_prop_value(prop=self._prop_target_temp)
if self._prop_target_temp
else None
)
@property @property
def current_operation(self) -> Optional[str]: def current_operation(self) -> Optional[str]:
@ -217,6 +210,4 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
return STATE_OFF return STATE_OFF
if not self._prop_mode and self.get_prop_value(prop=self._prop_on): if not self._prop_mode and self.get_prop_value(prop=self._prop_on):
return STATE_ON return STATE_ON
return self.get_map_description( return self._mode_map[self.get_prop_value(prop=self._prop_mode)]
map_=self._mode_map, key=self.get_prop_value(prop=self._prop_mode)
)