Store Shelly climate last_target_temp
value in restore extra data (#86482)
fixes undefined
This commit is contained in:
parent
b89a51c63d
commit
9a68f0abe8
2 changed files with 80 additions and 23 deletions
|
@ -25,7 +25,7 @@ from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
|||
|
||||
from . import init_integration, register_device, register_entity
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.common import mock_restore_cache, mock_restore_cache_with_extra_data
|
||||
|
||||
SENSOR_BLOCK_ID = 3
|
||||
DEVICE_BLOCK_ID = 4
|
||||
|
@ -191,19 +191,25 @@ async def test_block_restored_climate(hass, mock_block_device, device_reg, monke
|
|||
"sensor_0",
|
||||
entry,
|
||||
)
|
||||
mock_restore_cache(hass, [State(entity_id, HVACMode.HEAT)])
|
||||
attrs = {"current_temperature": 20.5, "temperature": 4.0}
|
||||
extra_data = {"last_target_temp": 22.0}
|
||||
mock_restore_cache_with_extra_data(
|
||||
hass, ((State(entity_id, HVACMode.OFF, attributes=attrs), extra_data),)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(mock_block_device, "initialized", False)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).state == HVACMode.OFF
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 4.0
|
||||
|
||||
# Partial update, should not change state
|
||||
mock_block_device.mock_update()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).state == HVACMode.OFF
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 4.0
|
||||
|
||||
# Make device online
|
||||
monkeypatch.setattr(mock_block_device, "initialized", True)
|
||||
|
@ -211,6 +217,24 @@ async def test_block_restored_climate(hass, mock_block_device, device_reg, monke
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == HVACMode.OFF
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 4.0
|
||||
|
||||
# Test set hvac mode heat, target temp should be set to last target temp (22)
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
mock_block_device.http_request.assert_called_once_with(
|
||||
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": 22.0}
|
||||
)
|
||||
|
||||
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 22.0)
|
||||
mock_block_device.mock_update()
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
assert state.state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 22.0
|
||||
|
||||
|
||||
async def test_block_restored_climate_us_customery(
|
||||
|
@ -229,36 +253,56 @@ async def test_block_restored_climate_us_customery(
|
|||
"sensor_0",
|
||||
entry,
|
||||
)
|
||||
attrs = {"current_temperature": 67, "temperature": 68}
|
||||
mock_restore_cache(hass, [State(entity_id, HVACMode.HEAT, attributes=attrs)])
|
||||
attrs = {"current_temperature": 67, "temperature": 39}
|
||||
extra_data = {"last_target_temp": 10.0}
|
||||
mock_restore_cache_with_extra_data(
|
||||
hass, ((State(entity_id, HVACMode.OFF, attributes=attrs), extra_data),)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(mock_block_device, "initialized", False)
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 68
|
||||
assert hass.states.get(entity_id).state == HVACMode.OFF
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 39
|
||||
assert hass.states.get(entity_id).attributes.get("current_temperature") == 67
|
||||
|
||||
# Partial update, should not change state
|
||||
mock_block_device.mock_update()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 68
|
||||
assert hass.states.get(entity_id).state == HVACMode.OFF
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 39
|
||||
assert hass.states.get(entity_id).attributes.get("current_temperature") == 67
|
||||
|
||||
# Make device online
|
||||
monkeypatch.setattr(mock_block_device, "initialized", True)
|
||||
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 19.7)
|
||||
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 4.0)
|
||||
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "temp", 18.2)
|
||||
mock_block_device.mock_update()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 67
|
||||
assert hass.states.get(entity_id).state == HVACMode.OFF
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 39
|
||||
assert hass.states.get(entity_id).attributes.get("current_temperature") == 65
|
||||
|
||||
# Test set hvac mode heat, target temp should be set to last target temp (10.0/50)
|
||||
await hass.services.async_call(
|
||||
CLIMATE_DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
mock_block_device.http_request.assert_called_once_with(
|
||||
"get", "thermostat/0", {"target_t_enabled": 1, "target_t": 10.0}
|
||||
)
|
||||
|
||||
monkeypatch.setattr(mock_block_device.blocks[SENSOR_BLOCK_ID], "targetTemp", 10.0)
|
||||
mock_block_device.mock_update()
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
assert state.state == HVACMode.HEAT
|
||||
assert hass.states.get(entity_id).attributes.get("temperature") == 50
|
||||
|
||||
|
||||
async def test_block_restored_climate_unavailable(
|
||||
hass, mock_block_device, device_reg, monkeypatch
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue