Replace hard coded attributes with constants for test cases in NUT (#141774)

Replace hard coded attributes with constants
This commit is contained in:
tdfountain 2025-03-29 18:19:41 -07:00 committed by GitHub
parent ed99686cc1
commit 2be2d54a5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,9 @@ import pytest
from homeassistant.components.nut.const import DOMAIN
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_FRIENDLY_NAME,
ATTR_UNIT_OF_MEASUREMENT,
CONF_HOST,
CONF_PORT,
CONF_RESOURCES,
@ -53,9 +56,9 @@ async def test_ups_devices(
assert state.state == "100"
expected_attributes = {
"device_class": "battery",
"friendly_name": "Ups1 Battery charge",
"unit_of_measurement": PERCENTAGE,
ATTR_DEVICE_CLASS: "battery",
ATTR_FRIENDLY_NAME: "Ups1 Battery charge",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
@ -88,9 +91,9 @@ async def test_ups_devices_with_unique_ids(
assert state.state == "100"
expected_attributes = {
"device_class": "battery",
"friendly_name": "Ups1 Battery charge",
"unit_of_measurement": PERCENTAGE,
ATTR_DEVICE_CLASS: "battery",
ATTR_FRIENDLY_NAME: "Ups1 Battery charge",
ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
@ -126,10 +129,10 @@ async def test_pdu_devices_with_unique_ids(
device_id="sensor.ups1_input_voltage",
state_value="122.91",
expected_attributes={
"device_class": SensorDeviceClass.VOLTAGE,
ATTR_DEVICE_CLASS: SensorDeviceClass.VOLTAGE,
"state_class": SensorStateClass.MEASUREMENT,
"friendly_name": "Ups1 Input voltage",
"unit_of_measurement": UnitOfElectricPotential.VOLT,
ATTR_FRIENDLY_NAME: "Ups1 Input voltage",
ATTR_UNIT_OF_MEASUREMENT: UnitOfElectricPotential.VOLT,
},
)
@ -141,8 +144,8 @@ async def test_pdu_devices_with_unique_ids(
device_id="sensor.ups1_ambient_humidity_status",
state_value="good",
expected_attributes={
"device_class": SensorDeviceClass.ENUM,
"friendly_name": "Ups1 Ambient humidity status",
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_FRIENDLY_NAME: "Ups1 Ambient humidity status",
},
)
@ -154,8 +157,8 @@ async def test_pdu_devices_with_unique_ids(
device_id="sensor.ups1_ambient_temperature_status",
state_value="good",
expected_attributes={
"device_class": SensorDeviceClass.ENUM,
"friendly_name": "Ups1 Ambient temperature status",
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_FRIENDLY_NAME: "Ups1 Ambient temperature status",
},
)
@ -305,9 +308,9 @@ async def test_pdu_dynamic_outlets(
device_id="sensor.ups1_outlet_a1_current",
state_value="0",
expected_attributes={
"device_class": SensorDeviceClass.CURRENT,
"friendly_name": "Ups1 Outlet A1 current",
"unit_of_measurement": UnitOfElectricCurrent.AMPERE,
ATTR_DEVICE_CLASS: SensorDeviceClass.CURRENT,
ATTR_FRIENDLY_NAME: "Ups1 Outlet A1 current",
ATTR_UNIT_OF_MEASUREMENT: UnitOfElectricCurrent.AMPERE,
},
)
@ -319,9 +322,9 @@ async def test_pdu_dynamic_outlets(
device_id="sensor.ups1_outlet_a24_current",
state_value="0.19",
expected_attributes={
"device_class": SensorDeviceClass.CURRENT,
"friendly_name": "Ups1 Outlet A24 current",
"unit_of_measurement": UnitOfElectricCurrent.AMPERE,
ATTR_DEVICE_CLASS: SensorDeviceClass.CURRENT,
ATTR_FRIENDLY_NAME: "Ups1 Outlet A24 current",
ATTR_UNIT_OF_MEASUREMENT: UnitOfElectricCurrent.AMPERE,
},
)