From a814da3b771e0bdb66da304bc80e2ec16833b37a Mon Sep 17 00:00:00 2001 From: Alone Date: Fri, 20 May 2022 20:55:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=B1=20add=20miio2miot=20for=20mmgg.fee?= =?UTF-8?q?der.petfeeder=20(#220=20#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/xiaomi_miot/config_flow.py | 8 + .../xiaomi_miot/core/device_customizes.py | 16 +- .../xiaomi_miot/core/miio2miot_specs.py | 26 +++ .../xiaomi_miot/core/miot_specs_extend.json | 201 +++++++++++++----- custom_components/xiaomi_miot/sensor.py | 18 +- custom_components/xiaomi_miot/switch.py | 7 +- .../xiaomi_miot/translations/en.json | 1 + 7 files changed, 205 insertions(+), 72 deletions(-) diff --git a/custom_components/xiaomi_miot/config_flow.py b/custom_components/xiaomi_miot/config_flow.py index 99301656f..204fb8ada 100644 --- a/custom_components/xiaomi_miot/config_flow.py +++ b/custom_components/xiaomi_miot/config_flow.py @@ -637,6 +637,10 @@ def get_customize_options(hass, options={}, bool2selects=[], entity_id='', model entity_class = attrs.get('entity_class') if domain == 'sensor': + if entity_class in ['MiotSensorEntity']: + options.update({ + 'state_property': cv.string, + }) options.update({ 'value_ratio': float, 'state_class': cv.string, @@ -662,6 +666,10 @@ def get_customize_options(hass, options={}, bool2selects=[], entity_id='', model options.update({ 'stat_power_cost_key': cv.string, }) + if entity_class in ['MiotSwitchActionSubEntity']: + options.update({ + 'feeding_measure': cv.positive_int, + }) if domain == 'light' or re.search(r'light', model, re.I): bool2selects.extend(['color_temp_reverse']) diff --git a/custom_components/xiaomi_miot/core/device_customizes.py b/custom_components/xiaomi_miot/core/device_customizes.py index fc39c9635..497b25569 100644 --- a/custom_components/xiaomi_miot/core/device_customizes.py +++ b/custom_components/xiaomi_miot/core/device_customizes.py @@ -339,18 +339,10 @@ 'cloud_delay_update': 10, }, 'mmgg.feeder.petfeeder': { - 'sensor_attributes': 'feed_today', - 'miio_commands': { - 'getprops': [ - 'food_status', 'feed_plan', 'door_result', 'feed_today', 'clean_days', 'outlet_status', - 'dryer_days', 'weight_level', 'wifi_led', 'key_lock', 'country_code', - ], - # 'getfeedplan1': [], - # 'getfeedplan2': [], - }, - 'miot_local_mapping': { - 'feeding.measure': {'siid': 2, 'piid': 1}, - }, + 'state_property': 'pet_food_left_level', + 'button_actions': 'reset_desiccant_life', + 'sensor_properties': 'feed_today,desiccant_left_time,cleantime', + 'switch_properties': 'feedstatus', }, 'miaomiaoce.sensor_ht.t1': { 'miot_mapping': { diff --git a/custom_components/xiaomi_miot/core/miio2miot_specs.py b/custom_components/xiaomi_miot/core/miio2miot_specs.py index d957bbb4e..3514b94f8 100644 --- a/custom_components/xiaomi_miot/core/miio2miot_specs.py +++ b/custom_components/xiaomi_miot/core/miio2miot_specs.py @@ -594,6 +594,32 @@ def cbk(prop, params, props, **kwargs): 'chunk_properties': 1, }, + 'mmgg.feeder.petfeeder': { + 'without_props': True, + 'miio_commands': [ + { + 'method': 'getprops', + 'values': [ + 'food_status', 'feed_status', 'door_status', 'feed_today', 'clean_days', 'outlet_status', + 'dryer_days', 'weight_level', 'wifi_led', 'key_lock', 'country_code', + ], + }, + ], + 'miio_specs': { + 'prop.2.101': {'prop': 'food_status'}, + 'prop.2.102': {'prop': 'feed_status', 'setter': 'stopfeed', 'set_template': '{{ [value|int] }}'}, + 'prop.2.103': {'prop': 'feed_today'}, + 'prop.2.104': {'prop': 'dryer_days'}, + 'prop.2.105': {'prop': 'clean_days'}, + 'prop.2.106': {'prop': 'door_status'}, + 'prop.2.107': {'prop': 'outlet_status'}, + 'action.2.1': {'setter': 'outfood'}, + 'action.2.101': {'setter': 'resetdryer'}, + 'prop.200.201': {'prop': 'wifi_led', 'setter': 'wifiledon', 'set_template': '{{ [value|int] }}'}, + 'prop.300.301': {'prop': 'key_lock', 'setter': 'keylock', 'set_template': '{{ [value|int] }}'}, + } + }, + 'opple.light.bydceiling': { 'without_props': True, 'miio_commands': [ diff --git a/custom_components/xiaomi_miot/core/miot_specs_extend.json b/custom_components/xiaomi_miot/core/miot_specs_extend.json index 10e37c32e..07e5c64a9 100644 --- a/custom_components/xiaomi_miot/core/miot_specs_extend.json +++ b/custom_components/xiaomi_miot/core/miot_specs_extend.json @@ -73,57 +73,6 @@ } ], - "dreame.vacuum.mc1808": [ - { - "iid": 18, - "properties": [ - { - "iid": 9, - "access": ["read", "notify"] - } - ] - } - ], - - "leshow.humidifier.jsq1": [ - { - "iid": 8, - "properties": [ - { - "iid": 5, - "access": ["read"] - }, - { - "iid": 6, - "access": ["read", "write"] - }, - { - "iid": 7, - "access": ["read"] - } - ] - } - ], - - "lumi.airer.acn01": [ - { - "iid": 2, - "properties": [ - { - "iid": 101, - "type": "urn:miot-spec-v2:property:dry_mode", - "format": "uint8", - "access": ["read", "write"], - "value-list": [ - {"value": 0, "description": "off"}, - {"value": 1, "description": "dry"}, - {"value": 2, "description": "winddry"} - ] - } - ] - } - ], - "deerma.humidifier.jsq": [ { "iid": 2, @@ -210,6 +159,156 @@ } ], + "dreame.vacuum.mc1808": [ + { + "iid": 18, + "properties": [ + { + "iid": 9, + "access": ["read", "notify"] + } + ] + } + ], + + "leshow.humidifier.jsq1": [ + { + "iid": 8, + "properties": [ + { + "iid": 5, + "access": ["read"] + }, + { + "iid": 6, + "access": ["read", "write"] + }, + { + "iid": 7, + "access": ["read"] + } + ] + } + ], + + "lumi.airer.acn01": [ + { + "iid": 2, + "properties": [ + { + "iid": 101, + "type": "urn:miot-spec-v2:property:dry_mode", + "format": "uint8", + "access": ["read", "write"], + "value-list": [ + {"value": 0, "description": "off"}, + {"value": 1, "description": "dry"}, + {"value": 2, "description": "winddry"} + ] + } + ] + } + ], + + "mmgg.feeder.petfeeder": [ + { + "iid": 2, + "properties": [ + { + "iid": 101, + "type": "urn:mmgg-spec:property:pet-food-left-level", + "format": "uint8", + "access": ["read"], + "value-list": [ + {"value": 0, "description": "Normal"}, + {"value": 1, "description": "Low"}, + {"value": 2, "description": "Empty"} + ] + }, + { + "iid": 102, + "type": "urn:miot-spec-v2:property:feedstatus", + "format": "bool", + "access": ["read", "write"] + }, + { + "iid": 103, + "type": "urn:mmgg-spec:property:feed-today", + "format": "uint8", + "access": ["read"], + "unit": "none", + "value-range": [0, 255, 1] + }, + { + "iid": 104, + "type": "urn:miot-spec-v2:property:desiccant-left-time", + "format": "uint16", + "access": ["read"], + "unit": "days", + "value-range": [0, 30, 1] + }, + { + "iid": 105, + "type": "urn:miot-spec-v2:property:cleantime", + "description": "Clean Left Time", + "format": "uint8", + "access": ["read"], + "unit": "days", + "value-range": [0, 14, 1] + }, + { + "iid": 106, + "type": "urn:mmgg-spec:property:doorstatus", + "format": "uint8", + "access": ["read", "notify"], + "unit": "none", + "value-range": [0, 1, 1] + }, + { + "iid": 107, + "type": "urn:mmgg-spec:property:outletstatus", + "format": "uint8", + "access": ["read", "notify"], + "unit": "none", + "value-range": [0, 1, 1] + } + ], + "actions": [ + { + "iid": 101, + "type": "urn:miot-spec-v2:action:reset-desiccant-life", + "in": [], + "out": [] + } + ] + }, + { + "iid": 200, + "type": "urn:miot-spec-v2:service:indicator-light", + "properties": [ + { + "iid": 201, + "type": "urn:miot-spec-v2:property:on", + "description": "Switch Status", + "format": "bool", + "access": ["read", "write"] + } + ] + }, + { + "iid": 300, + "type": "urn:miot-spec-v2:service:physical-controls-locked", + "properties": [ + { + "iid": 301, + "type": "urn:miot-spec-v2:property:physical-controls-locked", + "format": "bool", + "access": ["read", "write"] + } + ] + } + ], + "rockrobo.vacuum.v1": [ { "iid": 2, diff --git a/custom_components/xiaomi_miot/sensor.py b/custom_components/xiaomi_miot/sensor.py index a79f107d3..b3ec5df9e 100644 --- a/custom_components/xiaomi_miot/sensor.py +++ b/custom_components/xiaomi_miot/sensor.py @@ -120,7 +120,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= entities.append(MiotSensorEntity(config, srv)) for entity in entities: hass.data[DOMAIN]['entities'][entity.unique_id] = entity - async_add_entities(entities, update_before_add=True) + async_add_entities(entities, update_before_add=False) bind_services_to_entries(hass, SERVICE_TO_METHOD) @@ -153,17 +153,18 @@ def __init__(self, config, miot_service: MiotService): self._attr_state_class = None self._attr_native_unit_of_measurement = None + async def async_added_to_hass(self): + await super().async_added_to_hass() + if prop := self.custom_config('state_property'): + self._prop_state = self._miot_service.get_property(prop) or self._prop_state if self._prop_state: self._attr_icon = self._prop_state.entity_icon self._attr_device_class = self._prop_state.device_class self._attr_native_unit_of_measurement = self._prop_state.unit_of_measurement + self._state_attrs.update({ + 'state_property': self._prop_state.full_name, + }) - self._state_attrs.update({ - 'state_property': self._prop_state.full_name if self._prop_state else None, - }) - - async def async_added_to_hass(self): - await super().async_added_to_hass() cls = self.custom_config('state_class') if cls in STATE_CLASSES: self._attr_state_class = cls @@ -196,6 +197,9 @@ async def async_update(self): }) self._prop_state.description_to_dict(self._state_attrs) + async def async_update_for_main_entity(self): + await super().async_update_for_main_entity() + if self._miot_service.name in ['washer']: pls = self._miot_service.get_properties( 'mode', 'spin_speed', 'rinsh_times', diff --git a/custom_components/xiaomi_miot/switch.py b/custom_components/xiaomi_miot/switch.py index be0a6b261..215d36bb7 100644 --- a/custom_components/xiaomi_miot/switch.py +++ b/custom_components/xiaomi_miot/switch.py @@ -179,8 +179,11 @@ def is_on(self): def turn_on(self, **kwargs): """Turn the entity on.""" - val = None - if self._miot_property.value_range: + val = self.custom_config_integer(self._miot_property.name) + if val is not None: + # feeding_measure + pass + elif self._miot_property.value_range: val = int(self._miot_property.range_min() or 0) elif self._miot_property.value_list: val = self._miot_property.value_list[0].get('value') diff --git a/custom_components/xiaomi_miot/translations/en.json b/custom_components/xiaomi_miot/translations/en.json index ebc3bcbac..dea057ac8 100644 --- a/custom_components/xiaomi_miot/translations/en.json +++ b/custom_components/xiaomi_miot/translations/en.json @@ -80,6 +80,7 @@ "sources_via_keycodes": "sources_via_keycodes", "stat_power_cost_key": "stat_power_cost_key", "state_class": "state_class", + "state_property": "state_property", "switch_properties": "switch_properties", "unit_of_measurement": "unit_of_measurement", "value_ratio": "value_ratio",