mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use _attr_* in danfoss_air (#61341)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
b1a3ba2025
commit
3b80cbc495
@ -2,7 +2,7 @@
|
||||
from pydanfossair.commands import ReadCommand
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_OPENING,
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
|
||||
@ -14,7 +14,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
data = hass.data[DANFOSS_AIR_DOMAIN]
|
||||
|
||||
sensors = [
|
||||
["Danfoss Air Bypass Active", ReadCommand.bypass, DEVICE_CLASS_OPENING],
|
||||
[
|
||||
"Danfoss Air Bypass Active",
|
||||
ReadCommand.bypass,
|
||||
BinarySensorDeviceClass.OPENING,
|
||||
],
|
||||
["Danfoss Air Away Mode Active", ReadCommand.away_mode, None],
|
||||
]
|
||||
|
||||
@ -32,28 +36,12 @@ class DanfossAirBinarySensor(BinarySensorEntity):
|
||||
def __init__(self, data, name, sensor_type, device_class):
|
||||
"""Initialize the Danfoss Air binary sensor."""
|
||||
self._data = data
|
||||
self._name = name
|
||||
self._state = None
|
||||
self._attr_name = name
|
||||
self._type = sensor_type
|
||||
self._device_class = device_class
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Type of device class."""
|
||||
return self._device_class
|
||||
self._attr_device_class = device_class
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor."""
|
||||
self._data.update()
|
||||
|
||||
self._state = self._data.get_value(self._type)
|
||||
self._attr_is_on = self._data.get_value(self._type)
|
||||
|
@ -3,14 +3,12 @@ import logging
|
||||
|
||||
from pydanfossair.commands import ReadCommand
|
||||
|
||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
||||
|
||||
from . import DOMAIN as DANFOSS_AIR_DOMAIN
|
||||
|
||||
@ -26,29 +24,29 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"Danfoss Air Exhaust Temperature",
|
||||
TEMP_CELSIUS,
|
||||
ReadCommand.exhaustTemperature,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
],
|
||||
[
|
||||
"Danfoss Air Outdoor Temperature",
|
||||
TEMP_CELSIUS,
|
||||
ReadCommand.outdoorTemperature,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
],
|
||||
[
|
||||
"Danfoss Air Supply Temperature",
|
||||
TEMP_CELSIUS,
|
||||
ReadCommand.supplyTemperature,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
],
|
||||
[
|
||||
"Danfoss Air Extract Temperature",
|
||||
TEMP_CELSIUS,
|
||||
ReadCommand.extractTemperature,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
],
|
||||
[
|
||||
"Danfoss Air Remaining Filter",
|
||||
@ -61,8 +59,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"Danfoss Air Humidity",
|
||||
PERCENTAGE,
|
||||
ReadCommand.humidity,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorDeviceClass.HUMIDITY,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
],
|
||||
["Danfoss Air Fan Step", PERCENTAGE, ReadCommand.fan_step, None, None],
|
||||
[
|
||||
@ -83,7 +81,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"Danfoss Air Dial Battery",
|
||||
PERCENTAGE,
|
||||
ReadCommand.battery_percent,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
SensorDeviceClass.BATTERY,
|
||||
None,
|
||||
],
|
||||
]
|
||||
@ -104,33 +102,13 @@ class DanfossAir(SensorEntity):
|
||||
def __init__(self, data, name, sensor_unit, sensor_type, device_class, state_class):
|
||||
"""Initialize the sensor."""
|
||||
self._data = data
|
||||
self._name = name
|
||||
self._state = None
|
||||
self._attr_name = name
|
||||
self._attr_native_value = None
|
||||
self._type = sensor_type
|
||||
self._unit = sensor_unit
|
||||
self._device_class = device_class
|
||||
self._attr_native_unit_of_measurement = sensor_unit
|
||||
self._attr_device_class = device_class
|
||||
self._attr_state_class = state_class
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
def update(self):
|
||||
"""Update the new state of the sensor.
|
||||
|
||||
@ -139,6 +117,6 @@ class DanfossAir(SensorEntity):
|
||||
"""
|
||||
self._data.update()
|
||||
|
||||
self._state = self._data.get_value(self._type)
|
||||
if self._state is None:
|
||||
self._attr_native_value = self._data.get_value(self._type)
|
||||
if self._attr_native_value is None:
|
||||
_LOGGER.debug("Could not get data for %s", self._type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user