Add tests for additional nut ups models (#34240)

* Add NUT tests for an Eaton 5E650I UPS

* add a test to make sure multiple ups get setup

* Add a few more upses

* fix missing status key

* cover

* Force CI run
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-04-15 20:28:03 -05:00
1 parent 1f4cdda234
commit 188f3e35fd
6 files changed
+198 -4

No files matched your search

+13 -4
View File
@@ -27,7 +27,7 @@ async def test_form_user_one_ups(hass):
assert result["errors"] == {}
mock_pynut = _get_mock_pynutclient(
list_vars={"battery.voltage": "voltage"}, list_ups=["ups1"]
list_vars={"battery.voltage": "voltage", "ups.status": "OL"}, list_ups=["ups1"]
)
with patch(
@@ -54,7 +54,8 @@ async def test_form_user_one_ups(hass):
"homeassistant.components.nut.async_setup_entry", return_value=True,
) as mock_setup_entry:
result3 = await hass.config_entries.flow.async_configure(
result2["flow_id"], {"resources": ["battery.voltage"]},
result2["flow_id"],
{"resources": ["battery.voltage", "ups.status", "ups.status.display"]},
)
assert result3["type"] == "create_entry"
@@ -63,7 +64,7 @@ async def test_form_user_one_ups(hass):
"host": "1.1.1.1",
"password": "test-password",
"port": 2222,
"resources": ["battery.voltage"],
"resources": ["battery.voltage", "ups.status", "ups.status.display"],
"username": "test-username",
}
await hass.async_block_till_done()
@@ -74,6 +75,14 @@ async def test_form_user_one_ups(hass):
async def test_form_user_multiple_ups(hass):
"""Test we get the form."""
await setup.async_setup_component(hass, "persistent_notification", {})
config_entry = MockConfigEntry(
domain=DOMAIN,
data={"host": "2.2.2.2", "port": 123, "resources": ["battery.charge"]},
options={CONF_RESOURCES: ["battery.charge"]},
)
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
@@ -134,7 +143,7 @@ async def test_form_user_multiple_ups(hass):
}
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 2
async def test_form_import(hass):
+75
View File
@@ -80,6 +80,31 @@ async def test_5e850i(hass):
)
async def test_5e650i(hass):
"""Test creation of 5E650I sensors."""
await async_init_integration(hass, "5E650I", ["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 Battery Charging",
"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."""
@@ -132,3 +157,53 @@ async def test_cp1500pfclcd(hass):
assert all(
state.attributes[key] == expected_attributes[key] for key in expected_attributes
)
async def test_dl650elcd(hass):
"""Test creation of DL650ELCD sensors."""
await async_init_integration(hass, "DL650ELCD", ["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": UNIT_PERCENTAGE,
}
# 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_blazer_usb(hass):
"""Test creation of blazer_usb sensors."""
await async_init_integration(hass, "blazer_usb", ["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": UNIT_PERCENTAGE,
}
# 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
)