mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add unique ID for generic hygrostat (#101503)
This commit is contained in:
parent
9ac5bdc832
commit
475cb7719b
@ -2,7 +2,7 @@
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.humidifier import HumidifierDeviceClass
|
from homeassistant.components.humidifier import HumidifierDeviceClass
|
||||||
from homeassistant.const import CONF_NAME, Platform
|
from homeassistant.const import CONF_NAME, CONF_UNIQUE_ID, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv, discovery
|
from homeassistant.helpers import config_validation as cv, discovery
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
@ -24,6 +24,7 @@ CONF_AWAY_HUMIDITY = "away_humidity"
|
|||||||
CONF_AWAY_FIXED = "away_fixed"
|
CONF_AWAY_FIXED = "away_fixed"
|
||||||
CONF_STALE_DURATION = "sensor_stale_duration"
|
CONF_STALE_DURATION = "sensor_stale_duration"
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_TOLERANCE = 3
|
DEFAULT_TOLERANCE = 3
|
||||||
DEFAULT_NAME = "Generic Hygrostat"
|
DEFAULT_NAME = "Generic Hygrostat"
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ HYGROSTAT_SCHEMA = vol.Schema(
|
|||||||
vol.Optional(CONF_STALE_DURATION): vol.All(
|
vol.Optional(CONF_STALE_DURATION): vol.All(
|
||||||
cv.time_period, cv.positive_timedelta
|
cv.time_period, cv.positive_timedelta
|
||||||
),
|
),
|
||||||
|
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
|||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_MODE,
|
ATTR_MODE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
|
CONF_UNIQUE_ID,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -86,6 +87,7 @@ async def async_setup_platform(
|
|||||||
initial_state = config.get(CONF_INITIAL_STATE)
|
initial_state = config.get(CONF_INITIAL_STATE)
|
||||||
away_humidity = config.get(CONF_AWAY_HUMIDITY)
|
away_humidity = config.get(CONF_AWAY_HUMIDITY)
|
||||||
away_fixed = config.get(CONF_AWAY_FIXED)
|
away_fixed = config.get(CONF_AWAY_FIXED)
|
||||||
|
unique_id = config.get(CONF_UNIQUE_ID)
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
@ -105,6 +107,7 @@ async def async_setup_platform(
|
|||||||
away_humidity,
|
away_humidity,
|
||||||
away_fixed,
|
away_fixed,
|
||||||
sensor_stale_duration,
|
sensor_stale_duration,
|
||||||
|
unique_id,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -132,6 +135,7 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
|
|||||||
away_humidity,
|
away_humidity,
|
||||||
away_fixed,
|
away_fixed,
|
||||||
sensor_stale_duration,
|
sensor_stale_duration,
|
||||||
|
unique_id,
|
||||||
):
|
):
|
||||||
"""Initialize the hygrostat."""
|
"""Initialize the hygrostat."""
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -160,6 +164,7 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
|
|||||||
if not self._device_class:
|
if not self._device_class:
|
||||||
self._device_class = HumidifierDeviceClass.HUMIDIFIER
|
self._device_class = HumidifierDeviceClass.HUMIDIFIER
|
||||||
self._attr_action = HumidifierAction.IDLE
|
self._attr_action = HumidifierAction.IDLE
|
||||||
|
self._attr_unique_id = unique_id
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Run when entity about to be added."""
|
"""Run when entity about to be added."""
|
||||||
|
@ -31,6 +31,7 @@ from homeassistant.core import (
|
|||||||
State,
|
State,
|
||||||
callback,
|
callback,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
@ -169,6 +170,33 @@ async def test_humidifier_switch(
|
|||||||
assert hass.states.get(ENTITY).attributes.get("action") == "humidifying"
|
assert hass.states.get(ENTITY).attributes.get("action") == "humidifying"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unique_id(hass: HomeAssistant, setup_comp_1) -> None:
|
||||||
|
"""Test setting a unique ID."""
|
||||||
|
unique_id = "some_unique_id"
|
||||||
|
_setup_sensor(hass, 18)
|
||||||
|
await _setup_switch(hass, True)
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
DOMAIN,
|
||||||
|
{
|
||||||
|
"humidifier": {
|
||||||
|
"platform": "generic_hygrostat",
|
||||||
|
"name": "test",
|
||||||
|
"humidifier": ENT_SWITCH,
|
||||||
|
"target_sensor": ENT_SENSOR,
|
||||||
|
"unique_id": unique_id,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
|
entry = entity_registry.async_get(ENTITY)
|
||||||
|
assert entry
|
||||||
|
assert entry.unique_id == unique_id
|
||||||
|
|
||||||
|
|
||||||
def _setup_sensor(hass, humidity):
|
def _setup_sensor(hass, humidity):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
hass.states.async_set(ENT_SENSOR, humidity)
|
hass.states.async_set(ENT_SENSOR, humidity)
|
||||||
|
@ -174,7 +174,7 @@ async def test_heater_switch(
|
|||||||
|
|
||||||
|
|
||||||
async def test_unique_id(hass: HomeAssistant, setup_comp_1) -> None:
|
async def test_unique_id(hass: HomeAssistant, setup_comp_1) -> None:
|
||||||
"""Test heater switching input_boolean."""
|
"""Test setting a unique ID."""
|
||||||
unique_id = "some_unique_id"
|
unique_id = "some_unique_id"
|
||||||
_setup_sensor(hass, 18)
|
_setup_sensor(hass, 18)
|
||||||
_setup_switch(hass, True)
|
_setup_switch(hass, True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user