Skip to content

Commit

Permalink
Add state_class to ring battery sensor for LTS (#109872)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
livioavalle authored Feb 15, 2024
1 parent d49bccf commit c424720
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions homeassistant/components/ring/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
Expand Down Expand Up @@ -162,6 +163,7 @@ class RingSensorEntityDescription(SensorEntityDescription, RingRequiredKeysMixin
category=["doorbots", "authorized_doorbots", "stickup_cams"],
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
cls=RingSensor,
),
Expand Down
8 changes: 8 additions & 0 deletions tests/components/ring/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests_mock

from homeassistant.components.ring.const import SCAN_INTERVAL
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

Expand All @@ -22,10 +23,17 @@ async def test_sensor(hass: HomeAssistant, requests_mock: requests_mock.Mocker)
front_battery_state = hass.states.get("sensor.front_battery")
assert front_battery_state is not None
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")
assert front_door_battery_state is not None
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")
assert downstairs_volume_state is not None
Expand Down

0 comments on commit c424720

Please sign in to comment.