From 8b627ce69c8ac90ee83e41fc3c16b7e37d0f01c9 Mon Sep 17 00:00:00 2001 From: Simone Rossetto Date: Wed, 26 Oct 2022 19:10:00 +0200 Subject: [PATCH] Add room himidity entity if available --- custom_components/daikin_residential/const.py | 11 ++++++++++- custom_components/daikin_residential/daikin_base.py | 10 ++++++++-- custom_components/daikin_residential/sensor.py | 7 +++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/custom_components/daikin_residential/const.py b/custom_components/daikin_residential/const.py index fb9b2e0..864faea 100644 --- a/custom_components/daikin_residential/const.py +++ b/custom_components/daikin_residential/const.py @@ -8,10 +8,12 @@ CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ENERGY, DEVICE_CLASS_SIGNAL_STRENGTH, ENERGY_KILO_WATT_HOUR, TEMP_CELSIUS, + PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, ) @@ -37,7 +39,7 @@ ATTR_MAC_ADDRESS = "mac_address" ATTR_SERIAL_NUMBER = "serial_number" ATTR_ENERGY_CONSUMPTION = "energy_consumption" -ATTR_HUMIDITY = "humidity" +ATTR_ROOM_HUMIDITY = "room_humidity" ATTR_TARGET_HUMIDITY = "target_humidity" ATTR_FAN_MODE = "fan_mode" ATTR_FAN_SPEED = "fan_speed" @@ -69,6 +71,7 @@ ATTR_OPERATION_MODE: [MP_CLIMATE, DP_OPERATION_MODE, ""], ATTR_OUTSIDE_TEMPERATURE: [MP_CLIMATE, DP_SENSORS, "/outdoorTemperature"], ATTR_INSIDE_TEMPERATURE: [MP_CLIMATE, DP_SENSORS, "/roomTemperature"], + ATTR_ROOM_HUMIDITY: [MP_CLIMATE, DP_SENSORS, "/roomHumidity"], ATTR_TARGET_TEMPERATURE: [ MP_CLIMATE, DP_TEMPERATURE, @@ -142,6 +145,12 @@ CONF_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, CONF_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, }, + ATTR_ROOM_HUMIDITY: { + CONF_NAME: "Room Humidity", + CONF_TYPE: SENSOR_TYPE_HUMIDITY, + CONF_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY, + CONF_UNIT_OF_MEASUREMENT: PERCENTAGE, + }, ATTR_COOL_ENERGY: { CONF_NAME: "Cool Energy Consumption", CONF_TYPE: SENSOR_TYPE_ENERGY, diff --git a/custom_components/daikin_residential/daikin_base.py b/custom_components/daikin_residential/daikin_base.py index 697fc25..e14849e 100644 --- a/custom_components/daikin_residential/daikin_base.py +++ b/custom_components/daikin_residential/daikin_base.py @@ -8,6 +8,7 @@ PRESET_STREAMER, ATTR_INSIDE_TEMPERATURE, ATTR_OUTSIDE_TEMPERATURE, + ATTR_ROOM_HUMIDITY, ATTR_WIFI_STRENGTH, ATTR_WIFI_SSID, ATTR_LOCAL_SSID, @@ -276,9 +277,14 @@ async def async_set_swing_mode(self, mode): await self.setValue(ATTR_VSWING_MODE, new_vMode) @property - def support_humidity(self): + def support_room_humidity(self): """Return True if the device has humidity sensor.""" - return False + return self.getData(ATTR_ROOM_HUMIDITY) is not None + + @property + def room_humidity(self): + """Return current room humidity.""" + return self.getValue(ATTR_ROOM_HUMIDITY) if self.support_room_humidity else None @property def support_inside_temperature(self): diff --git a/custom_components/daikin_residential/sensor.py b/custom_components/daikin_residential/sensor.py index 806be3e..497f4ce 100644 --- a/custom_components/daikin_residential/sensor.py +++ b/custom_components/daikin_residential/sensor.py @@ -25,6 +25,7 @@ ATTR_HEAT_ENERGY, ATTR_INSIDE_TEMPERATURE, ATTR_OUTSIDE_TEMPERATURE, + ATTR_ROOM_HUMIDITY, ATTR_WIFI_STRENGTH, ATTR_WIFI_SSID, ATTR_LOCAL_SSID, @@ -62,6 +63,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities): _LOGGER.debug("device %s supports outside temperature", device.name) sensor = DaikinSensor.factory(device, ATTR_OUTSIDE_TEMPERATURE) sensors.append(sensor) + if device.support_room_humidity: + _LOGGER.debug("device %s supports room humidity", device.name) + sensor = DaikinSensor.factory(device, ATTR_ROOM_HUMIDITY) + sensors.append(sensor) if device.support_energy_consumption: _LOGGER.debug("device %s supports energy consumption", device.name) for period in SENSOR_PERIODS: @@ -177,6 +182,8 @@ def state(self): return self._device.inside_temperature if self._device_attribute == ATTR_OUTSIDE_TEMPERATURE: return self._device.outside_temperature + if self._device_attribute == ATTR_ROOM_HUMIDITY: + return self._device.room_humidity return None @property