Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 18, 2023
2 parents 9cb1d26 + 8bb4747 commit 21c1638
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
5 changes: 5 additions & 0 deletions custom_components/xiaomi_miot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,11 @@ def get_customize_options(hass, options={}, bool2selects=[], entity_id='', model
if domain == 'number':
bool2selects.extend(['restore_state'])

if domain == 'humidifier':
options.update({
'mode_property': cv.string,
})

if domain == 'device_tracker' or re.search(r'watch', model, re.I):
options.update({
'coord_type': cv.string,
Expand Down
20 changes: 20 additions & 0 deletions custom_components/xiaomi_miot/core/miio2miot_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,26 @@ def cbk(prop, params, props, **kwargs):
},
},
},
'viomi.health_pot.v1': {
# methods: ['set_voice', 'set_work', 'delete_modes', 'set_mode_sort', 'set_mode']
'miio_props': ['run_status', 'warm_data', 'last_time', 'last_temp', 'heat_power', 'warm_time', 'cook_time', 'cook_status', 'cooked_time', 'voice', 'stand_top_num', 'mode_sort'],
'entity_attrs': ['run_status', 'warm_data', 'last_time', 'last_temp', 'heat_power', 'warm_time', 'cook_time', 'cook_status', 'cooked_time', 'voice', 'stand_top_num', 'mode_sort'],
'chunk_properties': 1,
'miio_specs': {
'prop.2.1': {'prop': 'work_status', 'dict': {
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 6,
},
},
'prop.2.2': {'prop': 'left_time'},
'prop.2.3': {'prop': 'mode'},
'prop.2.4': {'prop': 'curr_tempe'},
},
},
'viomi.hood.v1': {
'chunk_properties': 1,
'miio_specs': {
Expand Down
22 changes: 22 additions & 0 deletions custom_components/xiaomi_miot/core/miot_specs_extend.json
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,28 @@
}
]
}
],

"zhimi.humidifier.ca4": [
{
"iid": 2,
"properties": [
{
"iid": 7,
"unit": "percentage",
"value-range": [0, 100, 1]
}
]
},
{
"iid": 7,
"properties": [
{
"iid": 1,
"unit": "rpm"
}
]
}
]

}
35 changes: 18 additions & 17 deletions custom_components/xiaomi_miot/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def __init__(self, config: dict, miot_service: MiotService):
super().__init__(miot_service, config=config, logger=_LOGGER)

self._prop_power = miot_service.get_property('on')
self._prop_mode = miot_service.get_property('mode')
self._prop_fan_level = miot_service.get_property('fan_level')
self._prop_water_level = miot_service.get_property('water_level')
self._prop_temperature = miot_service.get_property('temperature')
self._prop_target_humi = miot_service.get_property('target_humidity')
Expand All @@ -70,13 +68,16 @@ def __init__(self, config: dict, miot_service: MiotService):
self._prop_target_humi = self._environment.get_property('target_humidity') or self._prop_target_humi
self._prop_humidity = self._environment.get_property('relative_humidity', 'humidity') or self._prop_humidity

self._humidifier_mode = None
self._mode_props = [self._prop_mode, self._prop_fan_level]
self._mode_props = list(filter(lambda x: x, self._mode_props))
if self._mode_props:
self._humidifier_mode = self._mode_props.pop(0)
self._mode_props = list(filter(lambda x: x, [
miot_service.get_property('mode'),
miot_service.get_property('fan_level'),
]))
self._prop_mode = self._mode_props[0] if self._mode_props else None
if prop := self.custom_config('mode_property'):
if prop := self._miot_service.spec.get_property(prop):
self._prop_mode = prop
if self._prop_mode:
self._supported_features = HumidifierEntityFeature.MODES

async def async_added_to_hass(self):
await super().async_added_to_hass()
self._vars['target_humidity_ratio'] = self.custom_config_number('target_humidity_ratio')
Expand All @@ -103,7 +104,7 @@ async def async_update(self):
add_fans = self._add_entities.get('fan')
for p in self._mode_props:
pnm = p.full_name
if self._humidifier_mode and pnm == self._humidifier_mode.full_name:
if self._prop_mode and pnm == self._prop_mode.full_name:
continue
if pnm in self._subs:
self._subs[pnm].update_from_parent()
Expand Down Expand Up @@ -170,26 +171,26 @@ def max_humidity(self):
def mode(self):
if not self.is_on:
return MODE_OFF
if not self._humidifier_mode:
if not self._prop_mode:
return None
val = self._humidifier_mode.from_dict(self._state_attrs)
val = self._prop_mode.from_dict(self._state_attrs)
if val is None:
return None
return self._humidifier_mode.list_description(val)
return self._prop_mode.list_description(val)

@property
def available_modes(self):
mds = [MODE_OFF]
if self._humidifier_mode:
mds.extend(self._humidifier_mode.list_descriptions() or [])
if self._prop_mode:
mds.extend(self._prop_mode.list_descriptions() or [])
return mds

def set_mode(self, mode: str):
if mode == MODE_OFF:
return self.turn_off()
if not self._humidifier_mode:
if not self._prop_mode:
return False
val = self._humidifier_mode.list_value(mode)
val = self._prop_mode.list_value(mode)
if val is None:
return False
return self.set_property(self._humidifier_mode, val)
return self.set_property(self._prop_mode, val)
2 changes: 1 addition & 1 deletion custom_components/xiaomi_miot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"python-miio>=0.5.6",
"micloud>=0.3"
],
"version": "0.7.13"
"version": "0.7.14"
}

0 comments on commit 21c1638

Please sign in to comment.