mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Add generic_thermostat unique ID parameter (#46399)
* Add generic_thermostat unique ID parameter * Add tests for unique id * Fix flake8
This commit is contained in:
parent
26e7916367
commit
14a64ea970
@ -23,6 +23,7 @@ from homeassistant.const import (
|
|||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
|
CONF_UNIQUE_ID,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
PRECISION_HALVES,
|
PRECISION_HALVES,
|
||||||
PRECISION_TENTHS,
|
PRECISION_TENTHS,
|
||||||
@ -85,6 +86,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
vol.Optional(CONF_PRECISION): vol.In(
|
vol.Optional(CONF_PRECISION): vol.In(
|
||||||
[PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE]
|
[PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE]
|
||||||
),
|
),
|
||||||
|
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -109,6 +111,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
away_temp = config.get(CONF_AWAY_TEMP)
|
away_temp = config.get(CONF_AWAY_TEMP)
|
||||||
precision = config.get(CONF_PRECISION)
|
precision = config.get(CONF_PRECISION)
|
||||||
unit = hass.config.units.temperature_unit
|
unit = hass.config.units.temperature_unit
|
||||||
|
unique_id = config.get(CONF_UNIQUE_ID)
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
@ -128,6 +131,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
away_temp,
|
away_temp,
|
||||||
precision,
|
precision,
|
||||||
unit,
|
unit,
|
||||||
|
unique_id,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -153,6 +157,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||||||
away_temp,
|
away_temp,
|
||||||
precision,
|
precision,
|
||||||
unit,
|
unit,
|
||||||
|
unique_id,
|
||||||
):
|
):
|
||||||
"""Initialize the thermostat."""
|
"""Initialize the thermostat."""
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -177,6 +182,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||||||
self._max_temp = max_temp
|
self._max_temp = max_temp
|
||||||
self._target_temp = target_temp
|
self._target_temp = target_temp
|
||||||
self._unit = unit
|
self._unit = unit
|
||||||
|
self._unique_id = unique_id
|
||||||
self._support_flags = SUPPORT_FLAGS
|
self._support_flags = SUPPORT_FLAGS
|
||||||
if away_temp:
|
if away_temp:
|
||||||
self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
|
self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
|
||||||
@ -269,6 +275,11 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||||||
"""Return the name of the thermostat."""
|
"""Return the name of the thermostat."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return the unique id of this thermostat."""
|
||||||
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def precision(self):
|
def precision(self):
|
||||||
"""Return the precision of the system."""
|
"""Return the precision of the system."""
|
||||||
|
@ -159,6 +159,33 @@ async def test_heater_switch(hass, setup_comp_1):
|
|||||||
assert STATE_ON == hass.states.get(heater_switch).state
|
assert STATE_ON == hass.states.get(heater_switch).state
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unique_id(hass, setup_comp_1):
|
||||||
|
"""Test heater switching input_boolean."""
|
||||||
|
unique_id = "some_unique_id"
|
||||||
|
_setup_sensor(hass, 18)
|
||||||
|
_setup_switch(hass, True)
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
DOMAIN,
|
||||||
|
{
|
||||||
|
"climate": {
|
||||||
|
"platform": "generic_thermostat",
|
||||||
|
"name": "test",
|
||||||
|
"heater": ENT_SWITCH,
|
||||||
|
"target_sensor": ENT_SENSOR,
|
||||||
|
"unique_id": unique_id,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||||
|
|
||||||
|
entry = entity_registry.async_get(ENTITY)
|
||||||
|
assert entry
|
||||||
|
assert entry.unique_id == unique_id
|
||||||
|
|
||||||
|
|
||||||
def _setup_sensor(hass, temp):
|
def _setup_sensor(hass, temp):
|
||||||
"""Set up the test sensor."""
|
"""Set up the test sensor."""
|
||||||
hass.states.async_set(ENT_SENSOR, temp)
|
hass.states.async_set(ENT_SENSOR, temp)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user