Add ambient temperature and humidity status sensors to NUT (#124181)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
tdfountain
2025-02-24 06:09:43 -08:00
committed by GitHub
parent 5025e31129
commit 51a881f3b5
11 changed files with 724 additions and 9 deletions

View File

@@ -1,12 +1,19 @@
"""Test init of Nut integration."""
from copy import deepcopy
from unittest.mock import patch
from aionut import NUTError, NUTLoginError
from homeassistant.components.nut.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_HOST, CONF_PORT, STATE_UNAVAILABLE
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
CONF_PORT,
CONF_USERNAME,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@@ -147,3 +154,44 @@ async def test_device_location(hass: HomeAssistant) -> None:
assert device_entry is not None
assert device_entry.suggested_area == mock_device_location
async def test_update_options(hass: HomeAssistant) -> None:
"""Test update options triggers reload."""
mock_pynut = _get_mock_nutclient(
list_ups={"ups1": "UPS 1"}, list_vars={"ups.status": "OL"}
)
with patch(
"homeassistant.components.nut.AIONUTClient",
return_value=mock_pynut,
):
mock_config_entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "mock",
CONF_PASSWORD: "somepassword",
CONF_PORT: "mock",
CONF_USERNAME: "someuser",
},
options={
"device_options": {
"fake_option": "fake_option_value",
},
},
)
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert mock_config_entry.state is ConfigEntryState.LOADED
new_options = deepcopy(dict(mock_config_entry.options))
new_options["device_options"].clear()
hass.config_entries.async_update_entry(mock_config_entry, options=new_options)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert mock_config_entry.state is ConfigEntryState.LOADED