From 06d0227839b6bfc91b98ded7b349eb0c72b676dc Mon Sep 17 00:00:00 2001 From: Necroneco Date: Tue, 25 Jul 2023 00:12:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=80=BC=E7=B1=BB=E5=9E=8B=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/haier/core/attribute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/haier/core/attribute.py b/custom_components/haier/core/attribute.py index e6f1148..1ea84dc 100644 --- a/custom_components/haier/core/attribute.py +++ b/custom_components/haier/core/attribute.py @@ -93,7 +93,7 @@ def _parse_as_sensor(attribute): if attribute['type'] == 'enum': value_comparison_table = {} for item in attribute['variants']: - value_comparison_table[item['stdValue']] = item['description'] + value_comparison_table[str(item['stdValue'])] = item['description'] options['device_class'] = SensorDeviceClass.ENUM options['options'] = list(value_comparison_table.values()) From 5c7569561369f58145aaac3c2b513de51b498008 Mon Sep 17 00:00:00 2001 From: Necroneco Date: Tue, 25 Jul 2023 00:12:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=B8=80=E4=BA=9Bunit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/haier/core/attribute.py | 28 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/custom_components/haier/core/attribute.py b/custom_components/haier/core/attribute.py index 1ea84dc..2c55451 100644 --- a/custom_components/haier/core/attribute.py +++ b/custom_components/haier/core/attribute.py @@ -3,7 +3,7 @@ from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.switch import SwitchDeviceClass -from homeassistant.const import Platform, UnitOfTemperature, PERCENTAGE +from homeassistant.const import Platform, UnitOfTemperature, PERCENTAGE, UnitOfVolume, UnitOfEnergy, REVOLUTIONS_PER_MINUTE class HaierAttribute: @@ -100,12 +100,32 @@ def _parse_as_sensor(attribute): ext['value_comparison_table'] = value_comparison_table if isinstance(attribute['variants'], dict) and 'unit' in attribute['variants']: - if attribute['variants']['unit'] in ['L']: + if attribute['variants']['unit'] in ['L']: # 用水量 options['device_class'] = SensorDeviceClass.WATER + options['native_unit_of_measurement'] = UnitOfVolume.LITERS - if attribute['variants']['unit'] in ['℃']: + elif attribute['variants']['unit'] in ['℃']: # 温度 options['device_class'] = SensorDeviceClass.TEMPERATURE - options['unit_of_measurement'] = UnitOfTemperature.CELSIUS + options['native_unit_of_measurement'] = UnitOfTemperature.CELSIUS + + elif attribute['variants']['unit'] in ['%'] and '湿度' in attribute['description']: + options['device_class'] = SensorDeviceClass.HUMIDITY + options['native_unit_of_measurement'] = PERCENTAGE + + elif attribute['variants']['unit'] in ['KWh']: # 用电量 + options['device_class'] = SensorDeviceClass.ENERGY + options['native_unit_of_measurement'] = UnitOfEnergy.KILO_WATT_HOUR # kWh + + elif attribute['variants']['unit'] in ['h', 'min', 's']: # 时间 + options['device_class'] = SensorDeviceClass.DURATION + options['native_unit_of_measurement'] = attribute['variants']['unit'] + + elif attribute['variants']['unit'] in ['g', 'kg']: + options['device_class'] = SensorDeviceClass.WEIGHT + options['native_unit_of_measurement'] = attribute['variants']['unit'] + + elif attribute['variants']['unit'] in ['RPM']: # 转速 + options['native_unit_of_measurement'] = REVOLUTIONS_PER_MINUTE return HaierAttribute(attribute['name'], attribute['description'], Platform.SENSOR, options, ext)