mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Update generic_thermostat current_temperature on startup (#43951)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
fec623fb4e
commit
1d0b4290fe
@ -33,7 +33,7 @@ from homeassistant.const import (
|
|||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import DOMAIN as HA_DOMAIN, callback
|
from homeassistant.core import DOMAIN as HA_DOMAIN, CoreState, callback
|
||||||
from homeassistant.helpers import condition
|
from homeassistant.helpers import condition
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import (
|
from homeassistant.helpers.event import (
|
||||||
@ -207,7 +207,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_startup(event):
|
def _async_startup(*_):
|
||||||
"""Init on startup."""
|
"""Init on startup."""
|
||||||
sensor_state = self.hass.states.get(self.sensor_entity_id)
|
sensor_state = self.hass.states.get(self.sensor_entity_id)
|
||||||
if sensor_state and sensor_state.state not in (
|
if sensor_state and sensor_state.state not in (
|
||||||
@ -215,8 +215,12 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
):
|
):
|
||||||
self._async_update_temp(sensor_state)
|
self._async_update_temp(sensor_state)
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)
|
if self.hass.state == CoreState.running:
|
||||||
|
_async_startup()
|
||||||
|
else:
|
||||||
|
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)
|
||||||
|
|
||||||
# Check If we have an old state
|
# Check If we have an old state
|
||||||
old_state = await self.async_get_last_state()
|
old_state = await self.async_get_last_state()
|
||||||
|
@ -209,6 +209,30 @@ async def test_setup_defaults_to_unknown(hass):
|
|||||||
assert HVAC_MODE_OFF == hass.states.get(ENTITY).state
|
assert HVAC_MODE_OFF == hass.states.get(ENTITY).state
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_gets_current_temp_from_sensor(hass):
|
||||||
|
"""Test that current temperature is updated on entity addition."""
|
||||||
|
hass.config.units = METRIC_SYSTEM
|
||||||
|
_setup_sensor(hass, 18)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await async_setup_component(
|
||||||
|
hass,
|
||||||
|
DOMAIN,
|
||||||
|
{
|
||||||
|
"climate": {
|
||||||
|
"platform": "generic_thermostat",
|
||||||
|
"name": "test",
|
||||||
|
"cold_tolerance": 2,
|
||||||
|
"hot_tolerance": 4,
|
||||||
|
"heater": ENT_SWITCH,
|
||||||
|
"target_sensor": ENT_SENSOR,
|
||||||
|
"away_temp": 16,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert hass.states.get(ENTITY).attributes["current_temperature"] == 18
|
||||||
|
|
||||||
|
|
||||||
async def test_default_setup_params(hass, setup_comp_2):
|
async def test_default_setup_params(hass, setup_comp_2):
|
||||||
"""Test the setup with default parameters."""
|
"""Test the setup with default parameters."""
|
||||||
state = hass.states.get(ENTITY)
|
state = hass.states.get(ENTITY)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user