mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 07:51:46 -05:00
Add specific gravity velocity sensor to rapt_ble (#181518)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"specific_gravity_velocity": {
|
||||
"default": "mdi:trending-down"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,16 @@ SENSOR_DESCRIPTIONS: dict[tuple[str | None, str | None], SensorEntityDescription
|
||||
key=f"{DeviceClass.SPECIFIC_GRAVITY}_{Units.SPECIFIC_GRAVITY}",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
(
|
||||
DeviceClass.SPECIFIC_GRAVITY_VELOCITY,
|
||||
Units.SPECIFIC_GRAVITY_POINTS_PER_DAY,
|
||||
): SensorEntityDescription(
|
||||
key=f"{DeviceClass.SPECIFIC_GRAVITY_VELOCITY}_{Units.SPECIFIC_GRAVITY_POINTS_PER_DAY}",
|
||||
translation_key="specific_gravity_velocity",
|
||||
native_unit_of_measurement=Units.SPECIFIC_GRAVITY_POINTS_PER_DAY,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
suggested_display_precision=1,
|
||||
),
|
||||
(DeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(
|
||||
key=f"{DeviceClass.BATTERY}_{Units.PERCENTAGE}",
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
|
||||
@@ -8,9 +8,11 @@ from homeassistant.const import (
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
PERCENTAGE,
|
||||
STATE_UNKNOWN,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
|
||||
from . import (
|
||||
@@ -23,6 +25,8 @@ from . import (
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.bluetooth import inject_bluetooth_service_info
|
||||
|
||||
VELOCITY_ENTITY_ID = "sensor.rapt_pill_0666_specific_gravity_velocity"
|
||||
|
||||
|
||||
async def test_sensors(hass: HomeAssistant) -> None:
|
||||
"""Test setting up creates the sensors."""
|
||||
@@ -39,6 +43,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
||||
inject_bluetooth_service_info(hass, COMPLETE_SERVICE_INFO)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert hass.states.get(VELOCITY_ENTITY_ID) is None
|
||||
|
||||
temp_sensor = hass.states.get("sensor.rapt_pill_0666_battery")
|
||||
assert temp_sensor is not None
|
||||
@@ -73,16 +78,19 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"service_info",
|
||||
("service_info", "expected_state"),
|
||||
[
|
||||
pytest.param(V2_SERVICE_INFO, id="valid_velocity"),
|
||||
pytest.param(V2_NO_VELOCITY_SERVICE_INFO, id="invalid_velocity"),
|
||||
pytest.param(V2_SERVICE_INFO, "-14.8217964172363", id="valid_velocity"),
|
||||
pytest.param(V2_NO_VELOCITY_SERVICE_INFO, STATE_UNKNOWN, id="invalid_velocity"),
|
||||
],
|
||||
)
|
||||
async def test_sensors_v2_payload(
|
||||
hass: HomeAssistant, service_info: BluetoothServiceInfo
|
||||
async def test_specific_gravity_velocity_sensor(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
service_info: BluetoothServiceInfo,
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test a version 2 advertisement sets up the known sensors."""
|
||||
"""Test the specific gravity velocity sensor from a v2 payload."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=RAPT_MAC,
|
||||
@@ -94,8 +102,22 @@ async def test_sensors_v2_payload(
|
||||
|
||||
inject_bluetooth_service_info(hass, service_info)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert hass.states.get("sensor.rapt_pill_0666_specific_gravity") is not None
|
||||
assert len(hass.states.async_all()) == 4
|
||||
|
||||
velocity_sensor = hass.states.get(VELOCITY_ENTITY_ID)
|
||||
assert velocity_sensor is not None
|
||||
assert velocity_sensor.state == expected_state
|
||||
assert (
|
||||
velocity_sensor.attributes[ATTR_FRIENDLY_NAME]
|
||||
== "RAPT Pill 0666 Specific Gravity Velocity"
|
||||
)
|
||||
assert velocity_sensor.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||
assert velocity_sensor.attributes[ATTR_UNIT_OF_MEASUREMENT] == "SG points/day"
|
||||
|
||||
entity_entry = entity_registry.async_get(VELOCITY_ENTITY_ID)
|
||||
assert entity_entry is not None
|
||||
assert entity_entry.translation_key == "specific_gravity_velocity"
|
||||
assert entity_entry.options["sensor"]["suggested_display_precision"] == 1
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
Reference in New Issue
Block a user