Directly check string representation of sensor states in APCUPSD tests (#93783)

* Directly check the string representation of sensor states

* Fix expected state value for sensor.ups_nominal_output_power
This commit is contained in:
Yuxin Wang 2023-05-30 20:01:05 -04:00 committed by GitHub
parent fe472e6c5b
commit 0653aed49f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,4 @@
"""Test sensors of APCUPSd integration.""" """Test sensors of APCUPSd integration."""
import pytest
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
ATTR_STATE_CLASS, ATTR_STATE_CLASS,
@ -35,7 +34,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
# Test two representative voltage sensors. # Test two representative voltage sensors.
state = hass.states.get("sensor.ups_input_voltage") state = hass.states.get("sensor.ups_input_voltage")
assert state assert state
assert pytest.approx(float(state.state)) == 124.0 assert state.state == "124.0"
assert ( assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricPotential.VOLT state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricPotential.VOLT
) )
@ -47,7 +46,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
state = hass.states.get("sensor.ups_battery_voltage") state = hass.states.get("sensor.ups_battery_voltage")
assert state assert state
assert pytest.approx(float(state.state)) == 13.7 assert state.state == "13.7"
assert ( assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricPotential.VOLT state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfElectricPotential.VOLT
) )
@ -60,7 +59,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
# Test a representative percentage sensor. # Test a representative percentage sensor.
state = hass.states.get("sensor.ups_load") state = hass.states.get("sensor.ups_load")
assert state assert state
assert pytest.approx(float(state.state)) == 14.0 assert state.state == "14.0"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
entry = registry.async_get("sensor.ups_load") entry = registry.async_get("sensor.ups_load")
@ -70,7 +69,7 @@ async def test_sensor(hass: HomeAssistant) -> None:
# Test a representative wattage sensor. # Test a representative wattage sensor.
state = hass.states.get("sensor.ups_nominal_output_power") state = hass.states.get("sensor.ups_nominal_output_power")
assert state assert state
assert pytest.approx(float(state.state)) == 330.0 assert state.state == "330"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfPower.WATT
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
entry = registry.async_get("sensor.ups_nominal_output_power") entry = registry.async_get("sensor.ups_nominal_output_power")