mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 04:50:05 +00:00
Handle all zero serial numbers in NUT (#34045)
* Handle all zero serial numbers in NUT * Add additional nut tests * Update homeassistant/components/nut/__init__.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * remove re Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
@@ -9,6 +9,10 @@ async def test_pr3000rt2u(hass):
|
||||
"""Test creation of PR3000RT2U sensors."""
|
||||
|
||||
await async_init_integration(hass, "PR3000RT2U", ["battery.charge"])
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
entry = registry.async_get("sensor.ups1_battery_charge")
|
||||
assert entry
|
||||
assert entry.unique_id == "CPS_PR3000RT2U_PYVJO2000034_battery.charge"
|
||||
|
||||
state = hass.states.get("sensor.ups1_battery_charge")
|
||||
assert state.state == "100"
|
||||
@@ -30,6 +34,10 @@ async def test_cp1350c(hass):
|
||||
"""Test creation of CP1350C sensors."""
|
||||
|
||||
await async_init_integration(hass, "CP1350C", ["battery.charge"])
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
entry = registry.async_get("sensor.ups1_battery_charge")
|
||||
# No unique id, no registry entry
|
||||
assert not entry
|
||||
|
||||
state = hass.states.get("sensor.ups1_battery_charge")
|
||||
assert state.state == "100"
|
||||
@@ -51,6 +59,64 @@ async def test_5e850i(hass):
|
||||
"""Test creation of 5E850I sensors."""
|
||||
|
||||
await async_init_integration(hass, "5E850I", ["battery.charge"])
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
entry = registry.async_get("sensor.ups1_battery_charge")
|
||||
# No unique id, no registry entry
|
||||
assert not entry
|
||||
|
||||
state = hass.states.get("sensor.ups1_battery_charge")
|
||||
assert state.state == "100"
|
||||
|
||||
expected_attributes = {
|
||||
"device_class": "battery",
|
||||
"friendly_name": "Ups1 Battery Charge",
|
||||
"state": "Online",
|
||||
"unit_of_measurement": "%",
|
||||
}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
)
|
||||
|
||||
|
||||
async def test_backupsses600m1(hass):
|
||||
"""Test creation of BACKUPSES600M1 sensors."""
|
||||
|
||||
await async_init_integration(hass, "BACKUPSES600M1", ["battery.charge"])
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
entry = registry.async_get("sensor.ups1_battery_charge")
|
||||
# No unique id, no registry entry
|
||||
assert entry
|
||||
assert (
|
||||
entry.unique_id
|
||||
== "American Power Conversion_Back-UPS ES 600M1_4B1713P32195 _battery.charge"
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.ups1_battery_charge")
|
||||
assert state.state == "100"
|
||||
|
||||
expected_attributes = {
|
||||
"device_class": "battery",
|
||||
"friendly_name": "Ups1 Battery Charge",
|
||||
"state": "Online",
|
||||
"unit_of_measurement": "%",
|
||||
}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(
|
||||
state.attributes[key] == expected_attributes[key] for key in expected_attributes
|
||||
)
|
||||
|
||||
|
||||
async def test_cp1500pfclcd(hass):
|
||||
"""Test creation of CP1500PFCLCD sensors."""
|
||||
|
||||
await async_init_integration(hass, "CP1500PFCLCD", ["battery.charge"])
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
entry = registry.async_get("sensor.ups1_battery_charge")
|
||||
# No unique id, no registry entry
|
||||
assert not entry
|
||||
|
||||
state = hass.states.get("sensor.ups1_battery_charge")
|
||||
assert state.state == "100"
|
||||
|
||||
Reference in New Issue
Block a user