Fix Daikin integration power sensors ()

pull/52336/head
mlemainque 2021-06-30 12:01:08 +02:00 committed by GitHub
parent 3e4dacb885
commit a7ece4ecaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 6 deletions

View File

@ -5,10 +5,12 @@ from homeassistant.const import (
CONF_NAME,
CONF_TYPE,
CONF_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ,
PERCENTAGE,
POWER_KILO_WATT,
TEMP_CELSIUS,
@ -24,6 +26,7 @@ ATTR_COOL_ENERGY = "cool_energy"
ATTR_HEAT_ENERGY = "heat_energy"
ATTR_HUMIDITY = "humidity"
ATTR_TARGET_HUMIDITY = "target_humidity"
ATTR_COMPRESSOR_FREQUENCY = "compressor_frequency"
ATTR_STATE_ON = "on"
ATTR_STATE_OFF = "off"
@ -32,6 +35,7 @@ SENSOR_TYPE_TEMPERATURE = "temperature"
SENSOR_TYPE_HUMIDITY = "humidity"
SENSOR_TYPE_POWER = "power"
SENSOR_TYPE_ENERGY = "energy"
SENSOR_TYPE_FREQUENCY = "frequency"
SENSOR_TYPES = {
ATTR_INSIDE_TEMPERATURE: {
@ -68,14 +72,22 @@ SENSOR_TYPES = {
CONF_NAME: "Cool Energy Consumption",
CONF_TYPE: SENSOR_TYPE_ENERGY,
CONF_ICON: "mdi:snowflake",
CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
CONF_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
},
ATTR_HEAT_ENERGY: {
CONF_NAME: "Heat Energy Consumption",
CONF_TYPE: SENSOR_TYPE_ENERGY,
CONF_ICON: "mdi:fire",
CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
CONF_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
},
ATTR_COMPRESSOR_FREQUENCY: {
CONF_NAME: "Compressor Frequency",
CONF_TYPE: SENSOR_TYPE_FREQUENCY,
CONF_ICON: "mdi:fan",
CONF_UNIT_OF_MEASUREMENT: FREQUENCY_HERTZ,
},
}
CONF_UUID = "uuid"

View File

@ -3,7 +3,7 @@
"name": "Daikin AC",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/daikin",
"requirements": ["pydaikin==2.4.3"],
"requirements": ["pydaikin==2.4.4"],
"codeowners": ["@fredrike"],
"zeroconf": ["_dkapi._tcp.local."],
"quality_scale": "platinum",

View File

@ -10,6 +10,7 @@ from homeassistant.const import (
from . import DOMAIN as DAIKIN_DOMAIN, DaikinApi
from .const import (
ATTR_COMPRESSOR_FREQUENCY,
ATTR_COOL_ENERGY,
ATTR_HEAT_ENERGY,
ATTR_HUMIDITY,
@ -18,6 +19,7 @@ from .const import (
ATTR_TARGET_HUMIDITY,
ATTR_TOTAL_POWER,
SENSOR_TYPE_ENERGY,
SENSOR_TYPE_FREQUENCY,
SENSOR_TYPE_HUMIDITY,
SENSOR_TYPE_POWER,
SENSOR_TYPE_TEMPERATURE,
@ -46,6 +48,8 @@ async def async_setup_entry(hass, entry, async_add_entities):
if daikin_api.device.support_humidity:
sensors.append(ATTR_HUMIDITY)
sensors.append(ATTR_TARGET_HUMIDITY)
if daikin_api.device.support_compressor_frequency:
sensors.append(ATTR_COMPRESSOR_FREQUENCY)
async_add_entities([DaikinSensor.factory(daikin_api, sensor) for sensor in sensors])
@ -60,6 +64,7 @@ class DaikinSensor(SensorEntity):
SENSOR_TYPE_HUMIDITY: DaikinClimateSensor,
SENSOR_TYPE_POWER: DaikinPowerSensor,
SENSOR_TYPE_ENERGY: DaikinPowerSensor,
SENSOR_TYPE_FREQUENCY: DaikinClimateSensor,
}[SENSOR_TYPES[monitored_state][CONF_TYPE]]
return cls(api, monitored_state)
@ -125,6 +130,10 @@ class DaikinClimateSensor(DaikinSensor):
return self._api.device.humidity
if self._device_attribute == ATTR_TARGET_HUMIDITY:
return self._api.device.target_humidity
if self._device_attribute == ATTR_COMPRESSOR_FREQUENCY:
return self._api.device.compressor_frequency
return None
@ -135,9 +144,9 @@ class DaikinPowerSensor(DaikinSensor):
def state(self):
"""Return the state of the sensor."""
if self._device_attribute == ATTR_TOTAL_POWER:
return round(self._api.device.current_total_power_consumption, 3)
return round(self._api.device.current_total_power_consumption, 2)
if self._device_attribute == ATTR_COOL_ENERGY:
return round(self._api.device.last_hour_cool_energy_consumption, 3)
return round(self._api.device.last_hour_cool_energy_consumption, 2)
if self._device_attribute == ATTR_HEAT_ENERGY:
return round(self._api.device.last_hour_heat_energy_consumption, 3)
return round(self._api.device.last_hour_heat_energy_consumption, 2)
return None

View File

@ -1376,7 +1376,7 @@ pycsspeechtts==1.0.4
# pycups==1.9.73
# homeassistant.components.daikin
pydaikin==2.4.3
pydaikin==2.4.4
# homeassistant.components.danfoss_air
pydanfossair==0.1.0

View File

@ -774,7 +774,7 @@ pycomfoconnect==0.4
pycoolmasternet-async==0.1.2
# homeassistant.components.daikin
pydaikin==2.4.3
pydaikin==2.4.4
# homeassistant.components.deconz
pydeconz==80