mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add device classes to Dyson sensors (#45264)
This commit is contained in:
parent
e828e18156
commit
dcd17530cd
@ -4,14 +4,19 @@ import logging
|
|||||||
from libpurecool.dyson_pure_cool import DysonPureCool
|
from libpurecool.dyson_pure_cool import DysonPureCool
|
||||||
from libpurecool.dyson_pure_cool_link import DysonPureCoolLink
|
from libpurecool.dyson_pure_cool_link import DysonPureCoolLink
|
||||||
|
|
||||||
from homeassistant.const import PERCENTAGE, STATE_OFF, TEMP_CELSIUS, TIME_HOURS
|
from homeassistant.const import (
|
||||||
|
DEVICE_CLASS_HUMIDITY,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
PERCENTAGE,
|
||||||
|
STATE_OFF,
|
||||||
|
TEMP_CELSIUS,
|
||||||
|
TIME_HOURS,
|
||||||
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from . import DYSON_DEVICES, DysonEntity
|
from . import DYSON_DEVICES, DysonEntity
|
||||||
|
|
||||||
SENSOR_UNITS = {
|
SENSOR_UNITS = {
|
||||||
"air_quality": None,
|
|
||||||
"dust": None,
|
|
||||||
"filter_life": TIME_HOURS,
|
"filter_life": TIME_HOURS,
|
||||||
"carbon_filter_state": PERCENTAGE,
|
"carbon_filter_state": PERCENTAGE,
|
||||||
"hepa_filter_state": PERCENTAGE,
|
"hepa_filter_state": PERCENTAGE,
|
||||||
@ -26,8 +31,6 @@ SENSOR_ICONS = {
|
|||||||
"carbon_filter_state": "mdi:filter-outline",
|
"carbon_filter_state": "mdi:filter-outline",
|
||||||
"hepa_filter_state": "mdi:filter-outline",
|
"hepa_filter_state": "mdi:filter-outline",
|
||||||
"combi_filter_state": "mdi:filter-outline",
|
"combi_filter_state": "mdi:filter-outline",
|
||||||
"humidity": "mdi:water-percent",
|
|
||||||
"temperature": "mdi:thermometer",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SENSOR_NAMES = {
|
SENSOR_NAMES = {
|
||||||
@ -41,6 +44,11 @@ SENSOR_NAMES = {
|
|||||||
"temperature": "Temperature",
|
"temperature": "Temperature",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SENSOR_DEVICE_CLASSES = {
|
||||||
|
"humidity": DEVICE_CLASS_HUMIDITY,
|
||||||
|
"temperature": DEVICE_CLASS_TEMPERATURE,
|
||||||
|
}
|
||||||
|
|
||||||
DYSON_SENSOR_DEVICES = "dyson_sensor_devices"
|
DYSON_SENSOR_DEVICES = "dyson_sensor_devices"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -119,12 +127,17 @@ class DysonSensor(DysonEntity, Entity):
|
|||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
return SENSOR_UNITS[self._sensor_type]
|
return SENSOR_UNITS.get(self._sensor_type)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Return the icon for this sensor."""
|
"""Return the icon for this sensor."""
|
||||||
return SENSOR_ICONS[self._sensor_type]
|
return SENSOR_ICONS.get(self._sensor_type)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class of this sensor."""
|
||||||
|
return SENSOR_DEVICE_CLASSES.get(self._sensor_type)
|
||||||
|
|
||||||
|
|
||||||
class DysonFilterLifeSensor(DysonSensor):
|
class DysonFilterLifeSensor(DysonSensor):
|
||||||
|
@ -10,6 +10,8 @@ from homeassistant.components import dyson as dyson_parent
|
|||||||
from homeassistant.components.dyson import sensor as dyson
|
from homeassistant.components.dyson import sensor as dyson
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
|
DEVICE_CLASS_HUMIDITY,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
@ -203,6 +205,7 @@ class DysonTest(unittest.TestCase):
|
|||||||
assert sensor.unit_of_measurement == PERCENTAGE
|
assert sensor.unit_of_measurement == PERCENTAGE
|
||||||
assert sensor.name == "Device_name Humidity"
|
assert sensor.name == "Device_name Humidity"
|
||||||
assert sensor.entity_id == "sensor.dyson_1"
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
assert sensor.device_class == DEVICE_CLASS_HUMIDITY
|
||||||
|
|
||||||
def test_dyson_humidity_sensor_with_values(self):
|
def test_dyson_humidity_sensor_with_values(self):
|
||||||
"""Test humidity sensor with values."""
|
"""Test humidity sensor with values."""
|
||||||
@ -236,6 +239,7 @@ class DysonTest(unittest.TestCase):
|
|||||||
assert sensor.unit_of_measurement == TEMP_CELSIUS
|
assert sensor.unit_of_measurement == TEMP_CELSIUS
|
||||||
assert sensor.name == "Device_name Temperature"
|
assert sensor.name == "Device_name Temperature"
|
||||||
assert sensor.entity_id == "sensor.dyson_1"
|
assert sensor.entity_id == "sensor.dyson_1"
|
||||||
|
assert sensor.device_class == DEVICE_CLASS_TEMPERATURE
|
||||||
|
|
||||||
def test_dyson_temperature_sensor_with_values(self):
|
def test_dyson_temperature_sensor_with_values(self):
|
||||||
"""Test temperature sensor with values."""
|
"""Test temperature sensor with values."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user