Refactor SmartThings sensor platform (#138313)

This commit is contained in:
Joost Lekkerkerker 2025-02-11 18:14:13 +01:00 committed by GitHub
parent 8e7f35aa7d
commit 3489b20e86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 716 additions and 677 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,14 +4,9 @@ The only mocking required is of the underlying SmartThings API object so
real HTTP calls are not initiated during testing. real HTTP calls are not initiated during testing.
""" """
from pysmartthings import ATTRIBUTES, CAPABILITIES, Attribute, Capability from pysmartthings import Attribute, Capability
from homeassistant.components.sensor import ( from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
DEVICE_CLASSES,
DOMAIN as SENSOR_DOMAIN,
STATE_CLASSES,
)
from homeassistant.components.smartthings import sensor
from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE from homeassistant.components.smartthings.const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import ( from homeassistant.const import (
@ -29,20 +24,6 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform from .conftest import setup_platform
async def test_mapping_integrity() -> None:
"""Test ensures the map dicts have proper integrity."""
for capability, maps in sensor.CAPABILITY_TO_SENSORS.items():
assert capability in CAPABILITIES, capability
for sensor_map in maps:
assert sensor_map.attribute in ATTRIBUTES, sensor_map.attribute
if sensor_map.device_class:
assert sensor_map.device_class in DEVICE_CLASSES, (
sensor_map.device_class
)
if sensor_map.state_class:
assert sensor_map.state_class in STATE_CLASSES, sensor_map.state_class
async def test_entity_state(hass: HomeAssistant, device_factory) -> None: async def test_entity_state(hass: HomeAssistant, device_factory) -> None:
"""Tests the state attributes properly match the sensor types.""" """Tests the state attributes properly match the sensor types."""
device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100}) device = device_factory("Sensor 1", [Capability.battery], {Attribute.battery: 100})
@ -75,7 +56,9 @@ async def test_entity_three_axis_invalid_state(
) -> None: ) -> None:
"""Tests the state attributes properly match the three axis types.""" """Tests the state attributes properly match the three axis types."""
device = device_factory( device = device_factory(
"Three Axis", [Capability.three_axis], {Attribute.three_axis: []} "Three Axis",
[Capability.three_axis],
{Attribute.three_axis: [None, None, None]},
) )
await setup_platform(hass, SENSOR_DOMAIN, devices=[device]) await setup_platform(hass, SENSOR_DOMAIN, devices=[device])
state = hass.states.get("sensor.three_axis_x_coordinate") state = hass.states.get("sensor.three_axis_x_coordinate")