mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +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 pydanfossair.commands import ReadCommand
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_OPENING,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +14,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
data = hass.data[DANFOSS_AIR_DOMAIN]
|
data = hass.data[DANFOSS_AIR_DOMAIN]
|
||||||
|
|
||||||
sensors = [
|
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],
|
["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):
|
def __init__(self, data, name, sensor_type, device_class):
|
||||||
"""Initialize the Danfoss Air binary sensor."""
|
"""Initialize the Danfoss Air binary sensor."""
|
||||||
self._data = data
|
self._data = data
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._state = None
|
|
||||||
self._type = sensor_type
|
self._type = sensor_type
|
||||||
self._device_class = device_class
|
self._attr_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
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for the sensor."""
|
"""Fetch new state data for the sensor."""
|
||||||
self._data.update()
|
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 pydanfossair.commands import ReadCommand
|
||||||
|
|
||||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
from homeassistant.const import (
|
SensorDeviceClass,
|
||||||
DEVICE_CLASS_BATTERY,
|
SensorEntity,
|
||||||
DEVICE_CLASS_HUMIDITY,
|
SensorStateClass,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
PERCENTAGE,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
)
|
)
|
||||||
|
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
||||||
|
|
||||||
from . import DOMAIN as DANFOSS_AIR_DOMAIN
|
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",
|
"Danfoss Air Exhaust Temperature",
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
ReadCommand.exhaustTemperature,
|
ReadCommand.exhaustTemperature,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
SensorDeviceClass.TEMPERATURE,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorStateClass.MEASUREMENT,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"Danfoss Air Outdoor Temperature",
|
"Danfoss Air Outdoor Temperature",
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
ReadCommand.outdoorTemperature,
|
ReadCommand.outdoorTemperature,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
SensorDeviceClass.TEMPERATURE,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorStateClass.MEASUREMENT,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"Danfoss Air Supply Temperature",
|
"Danfoss Air Supply Temperature",
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
ReadCommand.supplyTemperature,
|
ReadCommand.supplyTemperature,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
SensorDeviceClass.TEMPERATURE,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorStateClass.MEASUREMENT,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"Danfoss Air Extract Temperature",
|
"Danfoss Air Extract Temperature",
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
ReadCommand.extractTemperature,
|
ReadCommand.extractTemperature,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
SensorDeviceClass.TEMPERATURE,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorStateClass.MEASUREMENT,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"Danfoss Air Remaining Filter",
|
"Danfoss Air Remaining Filter",
|
||||||
@ -61,8 +59,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
"Danfoss Air Humidity",
|
"Danfoss Air Humidity",
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
ReadCommand.humidity,
|
ReadCommand.humidity,
|
||||||
DEVICE_CLASS_HUMIDITY,
|
SensorDeviceClass.HUMIDITY,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorStateClass.MEASUREMENT,
|
||||||
],
|
],
|
||||||
["Danfoss Air Fan Step", PERCENTAGE, ReadCommand.fan_step, None, None],
|
["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",
|
"Danfoss Air Dial Battery",
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
ReadCommand.battery_percent,
|
ReadCommand.battery_percent,
|
||||||
DEVICE_CLASS_BATTERY,
|
SensorDeviceClass.BATTERY,
|
||||||
None,
|
None,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
@ -104,33 +102,13 @@ class DanfossAir(SensorEntity):
|
|||||||
def __init__(self, data, name, sensor_unit, sensor_type, device_class, state_class):
|
def __init__(self, data, name, sensor_unit, sensor_type, device_class, state_class):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._data = data
|
self._data = data
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._state = None
|
self._attr_native_value = None
|
||||||
self._type = sensor_type
|
self._type = sensor_type
|
||||||
self._unit = sensor_unit
|
self._attr_native_unit_of_measurement = sensor_unit
|
||||||
self._device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._attr_state_class = state_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):
|
def update(self):
|
||||||
"""Update the new state of the sensor.
|
"""Update the new state of the sensor.
|
||||||
|
|
||||||
@ -139,6 +117,6 @@ class DanfossAir(SensorEntity):
|
|||||||
"""
|
"""
|
||||||
self._data.update()
|
self._data.update()
|
||||||
|
|
||||||
self._state = self._data.get_value(self._type)
|
self._attr_native_value = self._data.get_value(self._type)
|
||||||
if self._state is None:
|
if self._attr_native_value is None:
|
||||||
_LOGGER.debug("Could not get data for %s", self._type)
|
_LOGGER.debug("Could not get data for %s", self._type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user