mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Add Device Type Energy to Srp Energy Sensor (#58147)
This commit is contained in:
parent
62c20860ac
commit
50686bd06d
@ -5,8 +5,12 @@ import logging
|
|||||||
import async_timeout
|
import async_timeout
|
||||||
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
|
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING, SensorEntity
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, ENERGY_KILO_WATT_HOUR
|
from homeassistant.const import (
|
||||||
|
ATTR_ATTRIBUTION,
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
)
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -137,6 +141,16 @@ class SrpEntity(SensorEntity):
|
|||||||
"""Return if entity is available."""
|
"""Return if entity is available."""
|
||||||
return self.coordinator.last_update_success
|
return self.coordinator.last_update_success
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class."""
|
||||||
|
return DEVICE_CLASS_ENERGY
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_class(self):
|
||||||
|
"""Return the state class."""
|
||||||
|
return STATE_CLASS_TOTAL_INCREASING
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""When entity is added to hass."""
|
"""When entity is added to hass."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Tests for the srp_energy sensor platform."""
|
"""Tests for the srp_energy sensor platform."""
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import STATE_CLASS_TOTAL_INCREASING
|
||||||
from homeassistant.components.srp_energy.const import (
|
from homeassistant.components.srp_energy.const import (
|
||||||
ATTRIBUTION,
|
ATTRIBUTION,
|
||||||
DEFAULT_NAME,
|
DEFAULT_NAME,
|
||||||
@ -10,7 +11,11 @@ from homeassistant.components.srp_energy.const import (
|
|||||||
SRP_ENERGY_DOMAIN,
|
SRP_ENERGY_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.components.srp_energy.sensor import SrpEntity, async_setup_entry
|
from homeassistant.components.srp_energy.sensor import SrpEntity, async_setup_entry
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION, ENERGY_KILO_WATT_HOUR
|
from homeassistant.const import (
|
||||||
|
ATTR_ATTRIBUTION,
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry(hass):
|
async def test_async_setup_entry(hass):
|
||||||
@ -94,6 +99,8 @@ async def test_srp_entity(hass):
|
|||||||
assert srp_entity.should_poll is False
|
assert srp_entity.should_poll is False
|
||||||
assert srp_entity.extra_state_attributes[ATTR_ATTRIBUTION] == ATTRIBUTION
|
assert srp_entity.extra_state_attributes[ATTR_ATTRIBUTION] == ATTRIBUTION
|
||||||
assert srp_entity.available is not None
|
assert srp_entity.available is not None
|
||||||
|
assert srp_entity.device_class == DEVICE_CLASS_ENERGY
|
||||||
|
assert srp_entity.state_class == STATE_CLASS_TOTAL_INCREASING
|
||||||
|
|
||||||
await srp_entity.async_added_to_hass()
|
await srp_entity.async_added_to_hass()
|
||||||
assert srp_entity.state is not None
|
assert srp_entity.state is not None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user