Add state_class to ring battery sensor for LTS (#109872)

* Add state_class to ring battery sensor for LTS

* Add test, in test_sensor.py, for state_class for battery entity; in response to comment in PR
This commit is contained in:
Livio Avalle 2024-02-15 16:52:11 +01:00 committed by GitHub
parent d49bccf123
commit c4247205ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -10,6 +10,7 @@ from homeassistant.components.sensor import (
SensorDeviceClass, SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -162,6 +163,7 @@ SENSOR_TYPES: tuple[RingSensorEntityDescription, ...] = (
category=["doorbots", "authorized_doorbots", "stickup_cams"], category=["doorbots", "authorized_doorbots", "stickup_cams"],
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
cls=RingSensor, cls=RingSensor,
), ),

View File

@ -5,6 +5,7 @@ from freezegun.api import FrozenDateTimeFactory
import requests_mock import requests_mock
from homeassistant.components.ring.const import SCAN_INTERVAL from homeassistant.components.ring.const import SCAN_INTERVAL
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -22,10 +23,17 @@ async def test_sensor(hass: HomeAssistant, requests_mock: requests_mock.Mocker)
front_battery_state = hass.states.get("sensor.front_battery") front_battery_state = hass.states.get("sensor.front_battery")
assert front_battery_state is not None assert front_battery_state is not None
assert front_battery_state.state == "80" assert front_battery_state.state == "80"
assert (
front_battery_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
)
front_door_battery_state = hass.states.get("sensor.front_door_battery") front_door_battery_state = hass.states.get("sensor.front_door_battery")
assert front_door_battery_state is not None assert front_door_battery_state is not None
assert front_door_battery_state.state == "100" assert front_door_battery_state.state == "100"
assert (
front_door_battery_state.attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
downstairs_volume_state = hass.states.get("sensor.downstairs_volume") downstairs_volume_state = hass.states.get("sensor.downstairs_volume")
assert downstairs_volume_state is not None assert downstairs_volume_state is not None