mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-18 16:10:44 +08:00
Compare commits
9 Commits
134854d93d
...
232018aec1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
232018aec1 | ||
|
|
d65fe32a98 | ||
|
|
50be2c5df9 | ||
|
|
b75cafb184 | ||
|
|
5438698a6e | ||
|
|
da90e099d1 | ||
|
|
2703d68920 | ||
|
|
694858e722 | ||
|
|
80931aaa42 |
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,5 +1,15 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## v0.1.5b0
|
||||||
|
### Added
|
||||||
|
- Add missing parameter state_class [#101](https://github.com/XiaoMi/ha_xiaomi_home/pull/101)
|
||||||
|
### Changed
|
||||||
|
- Make git update guide more accurate [#561](https://github.com/XiaoMi/ha_xiaomi_home/pull/561)
|
||||||
|
### Fixed
|
||||||
|
- Limit *light.mode count (value-range) [#535](https://github.com/XiaoMi/ha_xiaomi_home/pull/535)
|
||||||
|
- Update miot cloud raise error msg [#551](https://github.com/XiaoMi/ha_xiaomi_home/pull/551)
|
||||||
|
- Fix table header misplacement [#554](https://github.com/XiaoMi/ha_xiaomi_home/pull/554)
|
||||||
|
|
||||||
## v0.1.4
|
## v0.1.4
|
||||||
### Added
|
### Added
|
||||||
- Refactor miot network, add network detection logic, improve devices filter logic. [458](https://github.com/XiaoMi/ha_xiaomi_home/pull/458) [#191](https://github.com/XiaoMi/ha_xiaomi_home/pull/191)
|
- Refactor miot network, add network detection logic, improve devices filter logic. [458](https://github.com/XiaoMi/ha_xiaomi_home/pull/458) [#191](https://github.com/XiaoMi/ha_xiaomi_home/pull/191)
|
||||||
|
|||||||
@ -26,6 +26,7 @@ For example, update to version v1.0.0
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd config/ha_xiaomi_home
|
cd config/ha_xiaomi_home
|
||||||
|
git fetch
|
||||||
git checkout v1.0.0
|
git checkout v1.0.0
|
||||||
./install.sh /config
|
./install.sh /config
|
||||||
```
|
```
|
||||||
@ -140,7 +141,7 @@ In MIoT-Spec-V2 protocol, a product is defined as a device. A device contains se
|
|||||||
|
|
||||||
- Property
|
- Property
|
||||||
|
|
||||||
| format | access | value-list | value-range | Entity in Home Assistant |
|
| access | format | value-list | value-range | Entity in Home Assistant |
|
||||||
| ------------ | --------------------- | ------------ | ----------- | ------------------------ |
|
| ------------ | --------------------- | ------------ | ----------- | ------------------------ |
|
||||||
| writable | string | - | - | Text |
|
| writable | string | - | - | Text |
|
||||||
| writable | bool | - | - | Switch |
|
| writable | bool | - | - | Switch |
|
||||||
|
|||||||
@ -88,6 +88,9 @@ async def async_setup_entry(
|
|||||||
for data in miot_device.entity_list.get('heater', []):
|
for data in miot_device.entity_list.get('heater', []):
|
||||||
new_entities.append(
|
new_entities.append(
|
||||||
Heater(miot_device=miot_device, entity_data=data))
|
Heater(miot_device=miot_device, entity_data=data))
|
||||||
|
for data in miot_device.entity_list.get('bath-heater', []):
|
||||||
|
new_entities.append(
|
||||||
|
BathHeater(miot_device=miot_device, entity_data=data))
|
||||||
|
|
||||||
if new_entities:
|
if new_entities:
|
||||||
async_add_entities(new_entities)
|
async_add_entities(new_entities)
|
||||||
@ -617,3 +620,238 @@ class Heater(MIoTServiceEntity, ClimateEntity):
|
|||||||
map_=self._heat_level_map,
|
map_=self._heat_level_map,
|
||||||
key=self.get_prop_value(prop=self._prop_heat_level))
|
key=self.get_prop_value(prop=self._prop_heat_level))
|
||||||
if self._prop_heat_level else None)
|
if self._prop_heat_level else None)
|
||||||
|
|
||||||
|
class BathHeater(MIoTServiceEntity, ClimateEntity):
|
||||||
|
"""Heater entities for Xiaomi Home."""
|
||||||
|
# service: ptc-bath-heater
|
||||||
|
_prop_target_temp: Optional[MIoTSpecProperty]
|
||||||
|
_prop_heat_level: Optional[MIoTSpecProperty]
|
||||||
|
_prop_mode: Optional[MIoTSpecProperty]
|
||||||
|
_prop_env_temp: Optional[MIoTSpecProperty]
|
||||||
|
# service: fan-control
|
||||||
|
_prop_fan_on: Optional[MIoTSpecProperty]
|
||||||
|
_prop_fan_level: Optional[MIoTSpecProperty]
|
||||||
|
_prop_horizontal_swing: Optional[MIoTSpecProperty]
|
||||||
|
_prop_vertical_swing: Optional[MIoTSpecProperty]
|
||||||
|
|
||||||
|
_heat_level_map: Optional[dict[int, str]]
|
||||||
|
_hvac_mode_map: Optional[dict[int, HVACMode]]
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, miot_device: MIoTDevice, entity_data: MIoTEntityData
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the Bath Heater."""
|
||||||
|
super().__init__(miot_device=miot_device, entity_data=entity_data)
|
||||||
|
self._attr_icon = 'mdi:air-conditioner'
|
||||||
|
self._attr_supported_features = ClimateEntityFeature(0)
|
||||||
|
self._attr_preset_modes = []
|
||||||
|
self._attr_hvac_modes = []
|
||||||
|
self._attr_swing_modes = []
|
||||||
|
|
||||||
|
self._prop_mode = None
|
||||||
|
self._prop_target_temp = None
|
||||||
|
self._prop_heat_level = None
|
||||||
|
self._prop_env_temp = None
|
||||||
|
self._prop_fan_on = None
|
||||||
|
self._prop_fan_level = None
|
||||||
|
self._prop_horizontal_swing = None
|
||||||
|
self._prop_vertical_swing = None
|
||||||
|
self._heat_level_map = None
|
||||||
|
self._hvac_mode_map = None
|
||||||
|
|
||||||
|
# properties
|
||||||
|
for prop in entity_data.props:
|
||||||
|
if prop.name == 'target-temperature':
|
||||||
|
if not isinstance(prop.value_range, dict):
|
||||||
|
_LOGGER.error(
|
||||||
|
'invalid target-temperature value_range format, %s',
|
||||||
|
self.entity_id)
|
||||||
|
continue
|
||||||
|
self._attr_min_temp = prop.value_range['min']
|
||||||
|
self._attr_max_temp = prop.value_range['max']
|
||||||
|
self._attr_target_temperature_step = prop.value_range['step']
|
||||||
|
self._attr_temperature_unit = prop.external_unit
|
||||||
|
self._attr_supported_features |= (
|
||||||
|
ClimateEntityFeature.TARGET_TEMPERATURE)
|
||||||
|
self._prop_target_temp = prop
|
||||||
|
elif prop.name == 'heat-level':
|
||||||
|
if (
|
||||||
|
not isinstance(prop.value_list, list)
|
||||||
|
or not prop.value_list
|
||||||
|
):
|
||||||
|
_LOGGER.error(
|
||||||
|
'invalid heat-level value_list, %s', self.entity_id)
|
||||||
|
continue
|
||||||
|
self._heat_level_map = {
|
||||||
|
item['value']: item['description']
|
||||||
|
for item in prop.value_list}
|
||||||
|
self._attr_preset_modes = list(self._heat_level_map.values())
|
||||||
|
self._attr_supported_features |= (
|
||||||
|
ClimateEntityFeature.PRESET_MODE)
|
||||||
|
self._prop_heat_level = prop
|
||||||
|
elif prop.name == 'temperature':
|
||||||
|
self._prop_env_temp = prop
|
||||||
|
elif prop.name == 'mode':
|
||||||
|
if (
|
||||||
|
not isinstance(prop.value_list, list)
|
||||||
|
or not prop.value_list
|
||||||
|
):
|
||||||
|
_LOGGER.error(
|
||||||
|
'invalid mode value_list, %s', self.entity_id)
|
||||||
|
continue
|
||||||
|
self._hvac_mode_map = {}
|
||||||
|
for item in prop.value_list:
|
||||||
|
if item['name'].lower() in {'off', 'idle'}:
|
||||||
|
self._hvac_mode_map[item['value']] = HVACMode.OFF
|
||||||
|
elif item['name'].lower() in {'auto'}:
|
||||||
|
self._hvac_mode_map[item['value']] = HVACMode.AUTO
|
||||||
|
elif item['name'].lower() in {'heat', 'quick heat'}:
|
||||||
|
self._hvac_mode_map[item['value']] = HVACMode.HEAT
|
||||||
|
elif item['name'].lower() in {'dry'}:
|
||||||
|
self._hvac_mode_map[item['value']] = HVACMode.DRY
|
||||||
|
elif item['name'].lower() in {'fan', 'ventilate'}:
|
||||||
|
self._hvac_mode_map[item['value']] = HVACMode.FAN_ONLY
|
||||||
|
self._attr_hvac_modes = list(self._hvac_mode_map.values())
|
||||||
|
self._prop_mode = prop
|
||||||
|
elif prop.name == 'on':
|
||||||
|
if prop.service.name == 'fan-control':
|
||||||
|
self._attr_swing_modes.append(SWING_ON)
|
||||||
|
self._prop_fan_on = prop
|
||||||
|
elif prop.name == 'fan-level':
|
||||||
|
if (
|
||||||
|
not isinstance(prop.value_list, list)
|
||||||
|
or not prop.value_list
|
||||||
|
):
|
||||||
|
_LOGGER.error(
|
||||||
|
'invalid fan-level value_list, %s', self.entity_id)
|
||||||
|
continue
|
||||||
|
self._fan_mode_map = {
|
||||||
|
item['value']: item['description']
|
||||||
|
for item in prop.value_list}
|
||||||
|
self._attr_fan_modes = list(self._fan_mode_map.values())
|
||||||
|
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
||||||
|
self._prop_fan_level = prop
|
||||||
|
elif prop.name == 'horizontal-swing':
|
||||||
|
self._attr_swing_modes.append(SWING_HORIZONTAL)
|
||||||
|
self._prop_horizontal_swing = prop
|
||||||
|
elif prop.name == 'vertical-swing':
|
||||||
|
self._attr_swing_modes.append(SWING_VERTICAL)
|
||||||
|
# hvac modes
|
||||||
|
if HVACMode.OFF not in self._attr_hvac_modes:
|
||||||
|
self._attr_hvac_modes.append(HVACMode.OFF)
|
||||||
|
# swing modes
|
||||||
|
if (
|
||||||
|
SWING_HORIZONTAL in self._attr_swing_modes
|
||||||
|
and SWING_VERTICAL in self._attr_swing_modes
|
||||||
|
):
|
||||||
|
self._attr_swing_modes.append(SWING_BOTH)
|
||||||
|
if self._attr_swing_modes:
|
||||||
|
self._attr_swing_modes.insert(0, SWING_OFF)
|
||||||
|
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE
|
||||||
|
|
||||||
|
|
||||||
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
|
"""Set target hvac mode."""
|
||||||
|
# set mode
|
||||||
|
mode_value = self.get_map_value(
|
||||||
|
map_=self._hvac_mode_map, description=hvac_mode)
|
||||||
|
if (
|
||||||
|
mode_value is None or
|
||||||
|
not await self.set_property_async(
|
||||||
|
prop=self._prop_mode, value=mode_value)
|
||||||
|
):
|
||||||
|
raise RuntimeError(
|
||||||
|
f'set climate prop.mode failed, {hvac_mode}, {self.entity_id}')
|
||||||
|
|
||||||
|
async def async_set_temperature(self, **kwargs):
|
||||||
|
"""Set target temperature."""
|
||||||
|
if ATTR_TEMPERATURE in kwargs:
|
||||||
|
temp = kwargs[ATTR_TEMPERATURE]
|
||||||
|
if temp > self.max_temp:
|
||||||
|
temp = self.max_temp
|
||||||
|
elif temp < self.min_temp:
|
||||||
|
temp = self.min_temp
|
||||||
|
|
||||||
|
await self.set_property_async(
|
||||||
|
prop=self._prop_target_temp, value=temp)
|
||||||
|
|
||||||
|
async def async_set_swing_mode(self, swing_mode):
|
||||||
|
"""Set target swing operation."""
|
||||||
|
if swing_mode == SWING_BOTH:
|
||||||
|
if await self.set_property_async(
|
||||||
|
prop=self._prop_horizontal_swing, value=True, update=False):
|
||||||
|
self.set_prop_value(self._prop_horizontal_swing, value=True)
|
||||||
|
if await self.set_property_async(
|
||||||
|
prop=self._prop_vertical_swing, value=True, update=False):
|
||||||
|
self.set_prop_value(self._prop_vertical_swing, value=True)
|
||||||
|
elif swing_mode == SWING_HORIZONTAL:
|
||||||
|
if await self.set_property_async(
|
||||||
|
prop=self._prop_horizontal_swing, value=True, update=False):
|
||||||
|
self.set_prop_value(self._prop_horizontal_swing, value=True)
|
||||||
|
elif swing_mode == SWING_VERTICAL:
|
||||||
|
if await self.set_property_async(
|
||||||
|
prop=self._prop_vertical_swing, value=True, update=False):
|
||||||
|
self.set_prop_value(self._prop_vertical_swing, value=True)
|
||||||
|
elif swing_mode == SWING_ON:
|
||||||
|
if await self.set_property_async(
|
||||||
|
prop=self._prop_fan_on, value=True, update=False):
|
||||||
|
self.set_prop_value(self._prop_fan_on, value=True)
|
||||||
|
elif swing_mode == SWING_OFF:
|
||||||
|
if self._prop_fan_on and await self.set_property_async(
|
||||||
|
prop=self._prop_fan_on, value=False, update=False):
|
||||||
|
self.set_prop_value(self._prop_fan_on, value=False)
|
||||||
|
if self._prop_horizontal_swing and await self.set_property_async(
|
||||||
|
prop=self._prop_horizontal_swing, value=False,
|
||||||
|
update=False):
|
||||||
|
self.set_prop_value(self._prop_horizontal_swing, value=False)
|
||||||
|
if self._prop_vertical_swing and await self.set_property_async(
|
||||||
|
prop=self._prop_vertical_swing, value=False, update=False):
|
||||||
|
self.set_prop_value(self._prop_vertical_swing, value=False)
|
||||||
|
else:
|
||||||
|
raise RuntimeError(
|
||||||
|
f'unknown swing_mode, {swing_mode}, {self.entity_id}')
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
async def async_set_fan_mode(self, fan_mode):
|
||||||
|
"""Set target fan mode."""
|
||||||
|
mode_value = self.get_map_value(
|
||||||
|
map_=self._fan_mode_map, description=fan_mode)
|
||||||
|
if mode_value is None or not await self.set_property_async(
|
||||||
|
prop=self._prop_fan_level, value=mode_value):
|
||||||
|
raise RuntimeError(
|
||||||
|
f'set climate prop.fan_mode failed, {fan_mode}, '
|
||||||
|
f'{self.entity_id}')
|
||||||
|
|
||||||
|
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||||
|
"""Set the preset mode."""
|
||||||
|
await self.set_property_async(
|
||||||
|
self._prop_heat_level,
|
||||||
|
value=self.get_map_value(
|
||||||
|
map_=self._heat_level_map, description=preset_mode))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_temperature(self) -> Optional[float]:
|
||||||
|
"""Return the target temperature."""
|
||||||
|
return self.get_prop_value(
|
||||||
|
prop=self._prop_target_temp) if self._prop_target_temp else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_temperature(self) -> Optional[float]:
|
||||||
|
"""Return the current temperature."""
|
||||||
|
return self.get_prop_value(
|
||||||
|
prop=self._prop_env_temp) if self._prop_env_temp else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hvac_mode(self) -> Optional[HVACMode]:
|
||||||
|
"""Return the hvac mode. e.g., heat, idle mode."""
|
||||||
|
return self.get_map_description(
|
||||||
|
map_=self._hvac_mode_map,
|
||||||
|
key=self.get_prop_value(prop=self._prop_mode))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def preset_mode(self) -> Optional[str]:
|
||||||
|
return (
|
||||||
|
self.get_map_description(
|
||||||
|
map_=self._heat_level_map,
|
||||||
|
key=self.get_prop_value(prop=self._prop_heat_level))
|
||||||
|
if self._prop_heat_level else None)
|
||||||
|
|||||||
@ -95,6 +95,7 @@ async def async_setup_entry(
|
|||||||
class Light(MIoTServiceEntity, LightEntity):
|
class Light(MIoTServiceEntity, LightEntity):
|
||||||
"""Light entities for Xiaomi Home."""
|
"""Light entities for Xiaomi Home."""
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
_VALUE_RANGE_MODE_COUNT_MAX = 30
|
||||||
_prop_on: Optional[MIoTSpecProperty]
|
_prop_on: Optional[MIoTSpecProperty]
|
||||||
_prop_brightness: Optional[MIoTSpecProperty]
|
_prop_brightness: Optional[MIoTSpecProperty]
|
||||||
_prop_color_temp: Optional[MIoTSpecProperty]
|
_prop_color_temp: Optional[MIoTSpecProperty]
|
||||||
@ -147,13 +148,13 @@ class Light(MIoTServiceEntity, LightEntity):
|
|||||||
self._attr_supported_features |= LightEntityFeature.EFFECT
|
self._attr_supported_features |= LightEntityFeature.EFFECT
|
||||||
self._prop_mode = prop
|
self._prop_mode = prop
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.info(
|
||||||
'invalid brightness format, %s', self.entity_id)
|
'invalid brightness format, %s', self.entity_id)
|
||||||
continue
|
continue
|
||||||
# color-temperature
|
# color-temperature
|
||||||
if prop.name == 'color-temperature':
|
if prop.name == 'color-temperature':
|
||||||
if not isinstance(prop.value_range, dict):
|
if not isinstance(prop.value_range, dict):
|
||||||
_LOGGER.error(
|
_LOGGER.info(
|
||||||
'invalid color-temperature value_range format, %s',
|
'invalid color-temperature value_range format, %s',
|
||||||
self.entity_id)
|
self.entity_id)
|
||||||
continue
|
continue
|
||||||
@ -179,16 +180,29 @@ class Light(MIoTServiceEntity, LightEntity):
|
|||||||
for item in prop.value_list}
|
for item in prop.value_list}
|
||||||
elif isinstance(prop.value_range, dict):
|
elif isinstance(prop.value_range, dict):
|
||||||
mode_list = {}
|
mode_list = {}
|
||||||
for value in range(
|
if (
|
||||||
prop.value_range['min'], prop.value_range['max']):
|
int((
|
||||||
mode_list[value] = f'{value}'
|
prop.value_range['max']
|
||||||
|
- prop.value_range['min']
|
||||||
|
) / prop.value_range['step'])
|
||||||
|
> self._VALUE_RANGE_MODE_COUNT_MAX
|
||||||
|
):
|
||||||
|
_LOGGER.info(
|
||||||
|
'too many mode values, %s, %s, %s',
|
||||||
|
self.entity_id, prop.name, prop.value_range)
|
||||||
|
else:
|
||||||
|
for value in range(
|
||||||
|
prop.value_range['min'],
|
||||||
|
prop.value_range['max'],
|
||||||
|
prop.value_range['step']):
|
||||||
|
mode_list[value] = f'mode {value}'
|
||||||
if mode_list:
|
if mode_list:
|
||||||
self._mode_list = mode_list
|
self._mode_list = mode_list
|
||||||
self._attr_effect_list = list(self._mode_list.values())
|
self._attr_effect_list = list(self._mode_list.values())
|
||||||
self._attr_supported_features |= LightEntityFeature.EFFECT
|
self._attr_supported_features |= LightEntityFeature.EFFECT
|
||||||
self._prop_mode = prop
|
self._prop_mode = prop
|
||||||
else:
|
else:
|
||||||
_LOGGER.error('invalid mode format, %s', self.entity_id)
|
_LOGGER.info('invalid mode format, %s', self.entity_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not self._attr_supported_color_modes:
|
if not self._attr_supported_color_modes:
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
"cryptography",
|
"cryptography",
|
||||||
"psutil"
|
"psutil"
|
||||||
],
|
],
|
||||||
"version": "v0.1.4",
|
"version": "v0.1.5b0",
|
||||||
"zeroconf": [
|
"zeroconf": [
|
||||||
"_miot-central._tcp.local."
|
"_miot-central._tcp.local."
|
||||||
]
|
]
|
||||||
|
|||||||
@ -166,7 +166,7 @@ class MIoTOauthClient:
|
|||||||
key in res_obj['result']
|
key in res_obj['result']
|
||||||
for key in ['access_token', 'refresh_token', 'expires_in'])
|
for key in ['access_token', 'refresh_token', 'expires_in'])
|
||||||
):
|
):
|
||||||
raise MIoTOauthError(f'invalid http response, {http_res.text}')
|
raise MIoTOauthError(f'invalid http response, {res_str}')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
**res_obj['result'],
|
**res_obj['result'],
|
||||||
|
|||||||
@ -515,9 +515,15 @@ class MIoTDevice:
|
|||||||
prop.icon = self.icon_convert(prop.unit)
|
prop.icon = self.icon_convert(prop.unit)
|
||||||
device_class = SPEC_PROP_TRANS_MAP['properties'][prop_name][
|
device_class = SPEC_PROP_TRANS_MAP['properties'][prop_name][
|
||||||
'device_class']
|
'device_class']
|
||||||
prop.platform = device_class
|
result = {'platform': platform, 'device_class': device_class}
|
||||||
|
# optional:
|
||||||
return {'platform': platform, 'device_class': device_class}
|
if 'optional' in SPEC_PROP_TRANS_MAP['properties'][prop_name]:
|
||||||
|
optional = SPEC_PROP_TRANS_MAP['properties'][prop_name]['optional']
|
||||||
|
if 'state_class' in optional:
|
||||||
|
result['state_class'] = optional['state_class']
|
||||||
|
if not prop.unit and 'unit_of_measurement' in optional:
|
||||||
|
result['unit_of_measurement'] = optional['unit_of_measurement']
|
||||||
|
return result
|
||||||
|
|
||||||
def spec_transform(self) -> None:
|
def spec_transform(self) -> None:
|
||||||
"""Parse service, property, event, action from device spec."""
|
"""Parse service, property, event, action from device spec."""
|
||||||
@ -544,6 +550,13 @@ class MIoTDevice:
|
|||||||
if prop_entity:
|
if prop_entity:
|
||||||
prop.platform = prop_entity['platform']
|
prop.platform = prop_entity['platform']
|
||||||
prop.device_class = prop_entity['device_class']
|
prop.device_class = prop_entity['device_class']
|
||||||
|
if 'state_class' in prop_entity:
|
||||||
|
prop.state_class = prop_entity['state_class']
|
||||||
|
if 'unit_of_measurement' in prop_entity:
|
||||||
|
prop.external_unit = self.unit_convert(
|
||||||
|
prop_entity['unit_of_measurement'])
|
||||||
|
prop.icon = self.icon_convert(
|
||||||
|
prop_entity['unit_of_measurement'])
|
||||||
# general conversion
|
# general conversion
|
||||||
if not prop.platform:
|
if not prop.platform:
|
||||||
if prop.writable:
|
if prop.writable:
|
||||||
|
|||||||
@ -79,6 +79,7 @@ class MIoTSpecBase:
|
|||||||
# External params
|
# External params
|
||||||
platform: str
|
platform: str
|
||||||
device_class: Any
|
device_class: Any
|
||||||
|
state_class: Any
|
||||||
icon: str
|
icon: str
|
||||||
external_unit: Any
|
external_unit: Any
|
||||||
|
|
||||||
@ -96,6 +97,7 @@ class MIoTSpecBase:
|
|||||||
|
|
||||||
self.platform = None
|
self.platform = None
|
||||||
self.device_class = None
|
self.device_class = None
|
||||||
|
self.state_class = None
|
||||||
self.icon = None
|
self.icon = None
|
||||||
self.external_unit = None
|
self.external_unit = None
|
||||||
|
|
||||||
|
|||||||
@ -46,8 +46,16 @@ off Xiaomi or its affiliates' products.
|
|||||||
Conversion rules of MIoT-Spec-V2 instance to Home Assistant entity.
|
Conversion rules of MIoT-Spec-V2 instance to Home Assistant entity.
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.sensor import SensorDeviceClass
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
|
from homeassistant.components.sensor import SensorStateClass
|
||||||
from homeassistant.components.event import EventDeviceClass
|
from homeassistant.components.event import EventDeviceClass
|
||||||
|
|
||||||
|
from homeassistant.const import (
|
||||||
|
UnitOfEnergy,
|
||||||
|
UnitOfPower,
|
||||||
|
UnitOfElectricCurrent,
|
||||||
|
UnitOfElectricPotential,
|
||||||
|
)
|
||||||
|
|
||||||
# pylint: disable=pointless-string-statement
|
# pylint: disable=pointless-string-statement
|
||||||
"""SPEC_DEVICE_TRANS_MAP
|
"""SPEC_DEVICE_TRANS_MAP
|
||||||
{
|
{
|
||||||
@ -211,6 +219,7 @@ SPEC_DEVICE_TRANS_MAP: dict[str, dict | str] = {
|
|||||||
'entity': 'air-conditioner'
|
'entity': 'air-conditioner'
|
||||||
},
|
},
|
||||||
'air-condition-outlet': 'air-conditioner',
|
'air-condition-outlet': 'air-conditioner',
|
||||||
|
'thermostat': 'air-conditioner',
|
||||||
'heater': {
|
'heater': {
|
||||||
'required': {
|
'required': {
|
||||||
'heater': {
|
'heater': {
|
||||||
@ -233,6 +242,30 @@ SPEC_DEVICE_TRANS_MAP: dict[str, dict | str] = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
'entity': 'heater'
|
'entity': 'heater'
|
||||||
|
},
|
||||||
|
'bath-heater': {
|
||||||
|
'required': {
|
||||||
|
'ptc-bath-heater': {
|
||||||
|
'required': {},
|
||||||
|
'optional': {
|
||||||
|
'properties': {
|
||||||
|
'target-temperature', 'heat-level',
|
||||||
|
'temperature', 'mode'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'optional': {
|
||||||
|
'fan-control': {
|
||||||
|
'required': {},
|
||||||
|
'optional': {
|
||||||
|
'properties': {
|
||||||
|
'on', 'fan-level', 'horizontal-swing', 'vertical-swing'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'entity': 'bath-heater',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +358,11 @@ SPEC_SERVICE_TRANS_MAP: dict[str, dict | str] = {
|
|||||||
'properties': {
|
'properties': {
|
||||||
'<property instance name>':{
|
'<property instance name>':{
|
||||||
'device_class': str,
|
'device_class': str,
|
||||||
'entity': str
|
'entity': str,
|
||||||
|
'optional':{
|
||||||
|
'state_class': str,
|
||||||
|
'unit_of_measurement': str
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,7 +418,11 @@ SPEC_PROP_TRANS_MAP: dict[str, dict | str] = {
|
|||||||
},
|
},
|
||||||
'voltage': {
|
'voltage': {
|
||||||
'device_class': SensorDeviceClass.VOLTAGE,
|
'device_class': SensorDeviceClass.VOLTAGE,
|
||||||
'entity': 'sensor'
|
'entity': 'sensor',
|
||||||
|
'optional': {
|
||||||
|
'state_class': SensorStateClass.MEASUREMENT,
|
||||||
|
'unit_of_measurement': UnitOfElectricPotential.VOLT
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'illumination': {
|
'illumination': {
|
||||||
'device_class': SensorDeviceClass.ILLUMINANCE,
|
'device_class': SensorDeviceClass.ILLUMINANCE,
|
||||||
@ -391,6 +432,38 @@ SPEC_PROP_TRANS_MAP: dict[str, dict | str] = {
|
|||||||
'device_class': SensorDeviceClass.DURATION,
|
'device_class': SensorDeviceClass.DURATION,
|
||||||
'entity': 'sensor'
|
'entity': 'sensor'
|
||||||
},
|
},
|
||||||
|
'electric-power': {
|
||||||
|
'device_class': SensorDeviceClass.POWER,
|
||||||
|
'entity': 'sensor',
|
||||||
|
'optional': {
|
||||||
|
'state_class': SensorStateClass.MEASUREMENT,
|
||||||
|
'unit_of_measurement': UnitOfPower.WATT
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'electric-current': {
|
||||||
|
'device_class': SensorDeviceClass.CURRENT,
|
||||||
|
'entity': 'sensor',
|
||||||
|
'optional': {
|
||||||
|
'state_class': SensorStateClass.MEASUREMENT,
|
||||||
|
'unit_of_measurement': UnitOfElectricCurrent.AMPERE
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'power-consumption': {
|
||||||
|
'device_class': SensorDeviceClass.ENERGY,
|
||||||
|
'entity': 'sensor',
|
||||||
|
'optional': {
|
||||||
|
'state_class': SensorStateClass.TOTAL_INCREASING,
|
||||||
|
'unit_of_measurement': UnitOfEnergy.KILO_WATT_HOUR
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'total-battery': {
|
||||||
|
'device_class': SensorDeviceClass.ENERGY,
|
||||||
|
'entity': 'sensor',
|
||||||
|
'optional': {
|
||||||
|
'state_class': SensorStateClass.TOTAL_INCREASING,
|
||||||
|
'unit_of_measurement': UnitOfEnergy.KILO_WATT_HOUR
|
||||||
|
}
|
||||||
|
},
|
||||||
'has-someone-duration': 'no-one-determine-time',
|
'has-someone-duration': 'no-one-determine-time',
|
||||||
'no-one-duration': 'no-one-determine-time'
|
'no-one-duration': 'no-one-determine-time'
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,6 +106,9 @@ class Sensor(MIoTPropertyEntity, SensorEntity):
|
|||||||
# Set icon
|
# Set icon
|
||||||
if spec.icon:
|
if spec.icon:
|
||||||
self._attr_icon = spec.icon
|
self._attr_icon = spec.icon
|
||||||
|
# Set state_class
|
||||||
|
if spec.state_class:
|
||||||
|
self._attr_state_class = spec.state_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> Any:
|
def native_value(self) -> Any:
|
||||||
|
|||||||
@ -26,6 +26,7 @@ cd ha_xiaomi_home
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd config/ha_xiaomi_home
|
cd config/ha_xiaomi_home
|
||||||
|
git fetch
|
||||||
git checkout v1.0.0
|
git checkout v1.0.0
|
||||||
./install.sh /config
|
./install.sh /config
|
||||||
```
|
```
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user