mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add current device class to WLED current sensor (#38687)
This commit is contained in:
parent
c6105580bf
commit
3d0ea42ac0
@ -3,6 +3,7 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, Dict, List, Optional, Union
|
from typing import Any, Callable, Dict, List, Optional, Union
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import DEVICE_CLASS_CURRENT
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DATA_BYTES,
|
DATA_BYTES,
|
||||||
@ -105,6 +106,11 @@ class WLEDEstimatedCurrentSensor(WLEDSensor):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self.coordinator.data.info.leds.power
|
return self.coordinator.data.info.leds.power
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> Optional[str]:
|
||||||
|
"""Return the class of this sensor."""
|
||||||
|
return DEVICE_CLASS_CURRENT
|
||||||
|
|
||||||
|
|
||||||
class WLEDUptimeSensor(WLEDSensor):
|
class WLEDUptimeSensor(WLEDSensor):
|
||||||
"""Defines a WLED uptime sensor."""
|
"""Defines a WLED uptime sensor."""
|
||||||
|
@ -3,7 +3,10 @@ from datetime import datetime
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import (
|
||||||
|
DEVICE_CLASS_CURRENT,
|
||||||
|
DOMAIN as SENSOR_DOMAIN,
|
||||||
|
)
|
||||||
from homeassistant.components.wled.const import (
|
from homeassistant.components.wled.const import (
|
||||||
ATTR_LED_COUNT,
|
ATTR_LED_COUNT,
|
||||||
ATTR_MAX_POWER,
|
ATTR_MAX_POWER,
|
||||||
@ -12,6 +15,7 @@ from homeassistant.components.wled.const import (
|
|||||||
SIGNAL_DBM,
|
SIGNAL_DBM,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_ICON,
|
ATTR_ICON,
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
DATA_BYTES,
|
DATA_BYTES,
|
||||||
@ -94,6 +98,7 @@ async def test_sensors(
|
|||||||
assert state.attributes.get(ATTR_LED_COUNT) == 30
|
assert state.attributes.get(ATTR_LED_COUNT) == 30
|
||||||
assert state.attributes.get(ATTR_MAX_POWER) == 850
|
assert state.attributes.get(ATTR_MAX_POWER) == 850
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CURRENT_MA
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CURRENT_MA
|
||||||
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_CURRENT
|
||||||
assert state.state == "470"
|
assert state.state == "470"
|
||||||
|
|
||||||
entry = registry.async_get("sensor.wled_rgb_light_estimated_current")
|
entry = registry.async_get("sensor.wled_rgb_light_estimated_current")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user