mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add ambient state translations in NUT (#141772)
Add ambient state translations
This commit is contained in:
parent
c8d3fa6768
commit
7fbf15edc9
@ -83,9 +83,27 @@
|
||||
},
|
||||
"sensor": {
|
||||
"ambient_humidity": { "name": "Ambient humidity" },
|
||||
"ambient_humidity_status": { "name": "Ambient humidity status" },
|
||||
"ambient_humidity_status": {
|
||||
"name": "Ambient humidity status",
|
||||
"state": {
|
||||
"good": "Good",
|
||||
"warning-low": "Warning low",
|
||||
"critical-low": "Critical low",
|
||||
"warning-high": "Warning high",
|
||||
"critical-high": "Critical high"
|
||||
}
|
||||
},
|
||||
"ambient_temperature": { "name": "Ambient temperature" },
|
||||
"ambient_temperature_status": { "name": "Ambient temperature status" },
|
||||
"ambient_temperature_status": {
|
||||
"name": "Ambient temperature status",
|
||||
"state": {
|
||||
"good": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::good%]",
|
||||
"warning-low": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::warning-low%]",
|
||||
"critical-low": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::critical-low%]",
|
||||
"warning-high": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::warning-high%]",
|
||||
"critical-high": "[%key:component::nut::entity::sensor::ambient_humidity_status::state::critical-high%]"
|
||||
}
|
||||
},
|
||||
"battery_alarm_threshold": { "name": "Battery alarm threshold" },
|
||||
"battery_capacity": { "name": "Battery capacity" },
|
||||
"battery_charge": { "name": "Battery charge" },
|
||||
|
@ -15,11 +15,12 @@ from homeassistant.const import (
|
||||
CONF_RESOURCES,
|
||||
PERCENTAGE,
|
||||
STATE_UNKNOWN,
|
||||
Platform,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers import entity_registry as er, translation
|
||||
|
||||
from .util import (
|
||||
_get_mock_nutclient,
|
||||
@ -249,6 +250,36 @@ async def test_stale_options(
|
||||
assert state.state == "10"
|
||||
|
||||
|
||||
async def test_state_ambient_translation(hass: HomeAssistant) -> None:
|
||||
"""Test translation of ambient state sensor."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_HOST: "mock", CONF_PORT: "mock"},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
mock_pynut = _get_mock_nutclient(
|
||||
list_ups={"ups1": "UPS 1"}, list_vars={"ambient.humidity.status": "good"}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.nut.AIONUTClient",
|
||||
return_value=mock_pynut,
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
key = "ambient_humidity_status"
|
||||
state = hass.states.get(f"sensor.ups1_{key}")
|
||||
assert state.state == "good"
|
||||
|
||||
result = translation.async_translate_state(
|
||||
hass, state.state, Platform.SENSOR, DOMAIN, key, None
|
||||
)
|
||||
|
||||
assert result == "Good"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("model", "unique_id_base"),
|
||||
[
|
||||
|
Loading…
x
Reference in New Issue
Block a user