diff --git a/homeassistant/components/wled/binary_sensor.py b/homeassistant/components/wled/binary_sensor.py index 45df589de61..ce082691ffe 100644 --- a/homeassistant/components/wled/binary_sensor.py +++ b/homeassistant/components/wled/binary_sensor.py @@ -2,7 +2,7 @@ from __future__ import annotations from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_UPDATE, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry @@ -33,7 +33,7 @@ class WLEDUpdateBinarySensor(WLEDEntity, BinarySensorEntity): """Defines a WLED firmware binary sensor.""" _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC - _attr_device_class = DEVICE_CLASS_UPDATE + _attr_device_class = BinarySensorDeviceClass.UPDATE def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: """Initialize the button entity.""" diff --git a/homeassistant/components/wled/sensor.py b/homeassistant/components/wled/sensor.py index 271cba9055b..0bde4107688 100644 --- a/homeassistant/components/wled/sensor.py +++ b/homeassistant/components/wled/sensor.py @@ -8,16 +8,14 @@ from datetime import datetime, timedelta from wled import Device as WLEDDevice from homeassistant.components.sensor import ( - DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT, + SensorDeviceClass, SensorEntity, SensorEntityDescription, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( DATA_BYTES, - DEVICE_CLASS_SIGNAL_STRENGTH, - DEVICE_CLASS_TIMESTAMP, ELECTRIC_CURRENT_MILLIAMPERE, ENTITY_CATEGORY_DIAGNOSTIC, PERCENTAGE, @@ -52,7 +50,7 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = ( key="estimated_current", name="Estimated Current", native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE, - device_class=DEVICE_CLASS_CURRENT, + device_class=SensorDeviceClass.CURRENT, state_class=STATE_CLASS_MEASUREMENT, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, value_fn=lambda device: device.info.leds.power, @@ -68,13 +66,13 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = ( name="Max Current", native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - device_class=DEVICE_CLASS_CURRENT, + device_class=SensorDeviceClass.CURRENT, value_fn=lambda device: device.info.leds.max_power, ), WLEDSensorEntityDescription( key="uptime", name="Uptime", - device_class=DEVICE_CLASS_TIMESTAMP, + device_class=SensorDeviceClass.TIMESTAMP, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, value_fn=lambda device: (utcnow() - timedelta(seconds=device.info.uptime)), @@ -102,7 +100,7 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = ( key="wifi_rssi", name="Wi-Fi RSSI", native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - device_class=DEVICE_CLASS_SIGNAL_STRENGTH, + device_class=SensorDeviceClass.SIGNAL_STRENGTH, entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_registry_enabled_default=False, value_fn=lambda device: device.info.wifi.rssi if device.info.wifi else None, diff --git a/tests/components/wled/test_binary_sensor.py b/tests/components/wled/test_binary_sensor.py index 61a883b780c..5c40f8833e5 100644 --- a/tests/components/wled/test_binary_sensor.py +++ b/tests/components/wled/test_binary_sensor.py @@ -3,7 +3,7 @@ from unittest.mock import MagicMock import pytest -from homeassistant.components.binary_sensor import DEVICE_CLASS_UPDATE +from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_ICON, @@ -25,7 +25,7 @@ async def test_update_available( state = hass.states.get("binary_sensor.wled_rgb_light_firmware") assert state - assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_UPDATE + assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.UPDATE assert state.state == STATE_ON assert ATTR_ICON not in state.attributes @@ -44,7 +44,7 @@ async def test_no_update_available( state = hass.states.get("binary_sensor.wled_websocket_firmware") assert state - assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_UPDATE + assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.UPDATE assert state.state == STATE_OFF assert ATTR_ICON not in state.attributes diff --git a/tests/components/wled/test_sensor.py b/tests/components/wled/test_sensor.py index 7810915825d..bc401f574a6 100644 --- a/tests/components/wled/test_sensor.py +++ b/tests/components/wled/test_sensor.py @@ -4,12 +4,7 @@ from unittest.mock import MagicMock, patch import pytest -from homeassistant.components.sensor import ( - DEVICE_CLASS_CURRENT, - DEVICE_CLASS_SIGNAL_STRENGTH, - DEVICE_CLASS_TIMESTAMP, - DOMAIN as SENSOR_DOMAIN, -) +from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass from homeassistant.components.wled.const import DOMAIN from homeassistant.const import ( ATTR_DEVICE_CLASS, @@ -98,7 +93,7 @@ async def test_sensors( assert ( state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ELECTRIC_CURRENT_MILLIAMPERE ) - assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_CURRENT + assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.CURRENT assert state.state == "470" entry = registry.async_get("sensor.wled_rgb_light_estimated_current") @@ -108,7 +103,7 @@ async def test_sensors( state = hass.states.get("sensor.wled_rgb_light_uptime") assert state - assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TIMESTAMP + assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None assert state.state == "2019-11-11T09:10:00+00:00" @@ -143,7 +138,7 @@ async def test_sensors( state = hass.states.get("sensor.wled_rgb_light_wifi_rssi") assert state - assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_SIGNAL_STRENGTH + assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.SIGNAL_STRENGTH assert ( state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SIGNAL_STRENGTH_DECIBELS_MILLIWATT