Skip to content

Commit

Permalink
Update daikin sensors (#82441)
Browse files Browse the repository at this point in the history
fixes undefined
  • Loading branch information
mlemainque committed Nov 29, 2022
1 parent 33cd59d commit 0601028
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
7 changes: 2 additions & 5 deletions homeassistant/components/daikin/climate.py
Expand Up @@ -116,6 +116,8 @@ def format_target_temperature(target_temperature):
class DaikinClimate(ClimateEntity):
"""Representation of a Daikin HVAC."""

_attr_name = None
_attr_has_entity_name = True
_attr_temperature_unit = TEMP_CELSIUS

def __init__(self, api: DaikinApi) -> None:
Expand Down Expand Up @@ -173,11 +175,6 @@ async def _set(self, settings):
if values:
await self._api.device.set(values)

@property
def name(self):
"""Return the name of the thermostat, if any."""
return self._api.name

@property
def unique_id(self):
"""Return a unique ID."""
Expand Down
13 changes: 9 additions & 4 deletions homeassistant/components/daikin/const.py
Expand Up @@ -4,12 +4,17 @@
ATTR_TARGET_TEMPERATURE = "target_temperature"
ATTR_INSIDE_TEMPERATURE = "inside_temperature"
ATTR_OUTSIDE_TEMPERATURE = "outside_temperature"
ATTR_TOTAL_POWER = "total_power"
ATTR_COOL_ENERGY = "cool_energy"
ATTR_HEAT_ENERGY = "heat_energy"
ATTR_HUMIDITY = "humidity"

ATTR_TARGET_HUMIDITY = "target_humidity"
ATTR_HUMIDITY = "humidity"

ATTR_COMPRESSOR_FREQUENCY = "compressor_frequency"

ATTR_ENERGY_TODAY = "energy_today"
ATTR_COOL_ENERGY = "cool_energy"
ATTR_HEAT_ENERGY = "heat_energy"

ATTR_TOTAL_POWER = "total_power"
ATTR_TOTAL_ENERGY_TODAY = "total_energy_today"

ATTR_STATE_ON = "on"
Expand Down
34 changes: 24 additions & 10 deletions homeassistant/components/daikin/sensor.py
Expand Up @@ -29,6 +29,7 @@
from .const import (
ATTR_COMPRESSOR_FREQUENCY,
ATTR_COOL_ENERGY,
ATTR_ENERGY_TODAY,
ATTR_HEAT_ENERGY,
ATTR_HUMIDITY,
ATTR_INSIDE_TEMPERATURE,
Expand All @@ -54,15 +55,15 @@ class DaikinSensorEntityDescription(SensorEntityDescription, DaikinRequiredKeysM
SENSOR_TYPES: tuple[DaikinSensorEntityDescription, ...] = (
DaikinSensorEntityDescription(
key=ATTR_INSIDE_TEMPERATURE,
name="Inside Temperature",
name="Inside temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TEMP_CELSIUS,
value_func=lambda device: device.inside_temperature,
),
DaikinSensorEntityDescription(
key=ATTR_OUTSIDE_TEMPERATURE,
name="Outside Temperature",
name="Outside temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TEMP_CELSIUS,
Expand All @@ -78,51 +79,63 @@ class DaikinSensorEntityDescription(SensorEntityDescription, DaikinRequiredKeysM
),
DaikinSensorEntityDescription(
key=ATTR_TARGET_HUMIDITY,
name="Target Humidity",
name="Target humidity",
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
value_func=lambda device: device.humidity,
),
DaikinSensorEntityDescription(
key=ATTR_TOTAL_POWER,
name="Estimated Power Consumption",
name="Compressor estimated power consumption",
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_KILO_WATT,
value_func=lambda device: round(device.current_total_power_consumption, 2),
),
DaikinSensorEntityDescription(
key=ATTR_COOL_ENERGY,
name="Cool Energy Consumption",
name="Cool energy consumption",
icon="mdi:snowflake",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
entity_registry_enabled_default=False,
value_func=lambda device: round(device.last_hour_cool_energy_consumption, 2),
),
DaikinSensorEntityDescription(
key=ATTR_HEAT_ENERGY,
name="Heat Energy Consumption",
name="Heat energy consumption",
icon="mdi:fire",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
entity_registry_enabled_default=False,
value_func=lambda device: round(device.last_hour_heat_energy_consumption, 2),
),
DaikinSensorEntityDescription(
key=ATTR_ENERGY_TODAY,
name="Energy consumption",
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_func=lambda device: round(device.today_energy_consumption, 2),
),
DaikinSensorEntityDescription(
key=ATTR_COMPRESSOR_FREQUENCY,
name="Compressor Frequency",
name="Compressor frequency",
icon="mdi:fan",
device_class=SensorDeviceClass.FREQUENCY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=FREQUENCY_HERTZ,
entity_registry_enabled_default=False,
value_func=lambda device: device.compressor_frequency,
),
DaikinSensorEntityDescription(
key=ATTR_TOTAL_ENERGY_TODAY,
name="Today's Total Energy Consumption",
name="Compressor energy consumption",
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
entity_registry_enabled_default=False,
value_func=lambda device: round(device.today_total_energy_consumption, 2),
),
)
Expand Down Expand Up @@ -150,9 +163,10 @@ async def async_setup_entry(
if daikin_api.device.support_outside_temperature:
sensors.append(ATTR_OUTSIDE_TEMPERATURE)
if daikin_api.device.support_energy_consumption:
sensors.append(ATTR_TOTAL_POWER)
sensors.append(ATTR_ENERGY_TODAY)
sensors.append(ATTR_COOL_ENERGY)
sensors.append(ATTR_HEAT_ENERGY)
sensors.append(ATTR_TOTAL_POWER)
sensors.append(ATTR_TOTAL_ENERGY_TODAY)
if daikin_api.device.support_humidity:
sensors.append(ATTR_HUMIDITY)
Expand All @@ -171,6 +185,7 @@ async def async_setup_entry(
class DaikinSensor(SensorEntity):
"""Representation of a Sensor."""

_attr_has_entity_name = True
entity_description: DaikinSensorEntityDescription

def __init__(
Expand All @@ -179,7 +194,6 @@ def __init__(
"""Initialize the sensor."""
self.entity_description = description
self._api = api
self._attr_name = f"{api.name} {description.name}"

@property
def unique_id(self) -> str:
Expand Down
24 changes: 8 additions & 16 deletions homeassistant/components/daikin/switch.py
Expand Up @@ -56,6 +56,9 @@ async def async_setup_entry(
class DaikinZoneSwitch(SwitchEntity):
"""Representation of a zone."""

_attr_icon = ZONE_ICON
_attr_has_entity_name = True

def __init__(self, daikin_api: DaikinApi, zone_id):
"""Initialize the zone."""
self._api = daikin_api
Expand All @@ -66,15 +69,10 @@ def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._api.device.mac}-zone{self._zone_id}"

@property
def icon(self):
"""Icon to use in the frontend, if any."""
return ZONE_ICON

@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{self._api.name} {self._api.device.zones[self._zone_id][0]}"
return self._api.device.zones[self._zone_id][0]

@property
def is_on(self) -> bool:
Expand Down Expand Up @@ -102,6 +100,10 @@ async def async_turn_off(self, **kwargs: Any) -> None:
class DaikinStreamerSwitch(SwitchEntity):
"""Streamer state."""

_attr_icon = STREAMER_ICON
_attr_name = "Streamer"
_attr_has_entity_name = True

def __init__(self, daikin_api: DaikinApi) -> None:
"""Initialize streamer switch."""
self._api = daikin_api
Expand All @@ -111,16 +113,6 @@ def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._api.device.mac}-streamer"

@property
def icon(self):
"""Icon to use in the frontend, if any."""
return STREAMER_ICON

@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{self._api.name} streamer"

@property
def is_on(self) -> bool:
"""Return the state of the sensor."""
Expand Down

0 comments on commit 0601028

Please sign in to comment.