init home-assistant

This commit is contained in:
2026-11-19 15:15:32 -05:00
parent 2e81d9d300
commit feec6ef9fb
19230 changed files with 3335526 additions and 0 deletions

View File

@@ -0,0 +1 @@
"""maxcube tests."""

View File

@@ -0,0 +1,123 @@
"""Tests for EQ3 Max! component."""
from unittest.mock import create_autospec, patch
from maxcube.device import MAX_DEVICE_MODE_AUTOMATIC, MAX_DEVICE_MODE_MANUAL
from maxcube.room import MaxRoom
from maxcube.thermostat import MaxThermostat
from maxcube.wallthermostat import MaxWallThermostat
from maxcube.windowshutter import MaxWindowShutter
import pytest
from homeassistant.components.maxcube import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component
from homeassistant.util.dt import now
@pytest.fixture
def room():
"""Create a test MAX! room."""
r = MaxRoom()
r.id = 1
r.name = "TestRoom"
return r
@pytest.fixture
def thermostat():
"""Create test MAX! thermostat."""
t = create_autospec(MaxThermostat)
t.name = "TestThermostat"
t.serial = "AABBCCDD01"
t.rf_address = "abc1"
t.room_id = 1
t.is_thermostat.return_value = True
t.is_wallthermostat.return_value = False
t.is_windowshutter.return_value = False
t.mode = MAX_DEVICE_MODE_AUTOMATIC
t.comfort_temperature = 19.0
t.eco_temperature = 14.0
t.target_temperature = 20.5
t.actual_temperature = 19.0
t.max_temperature = None
t.min_temperature = None
t.valve_position = 25 # 25%
t.battery = 1
return t
@pytest.fixture
def wallthermostat():
"""Create test MAX! wall thermostat."""
t = create_autospec(MaxWallThermostat)
t.name = "TestWallThermostat"
t.serial = "AABBCCDD02"
t.rf_address = "abc2"
t.room_id = 1
t.is_thermostat.return_value = False
t.is_wallthermostat.return_value = True
t.is_windowshutter.return_value = False
t.mode = MAX_DEVICE_MODE_MANUAL
t.comfort_temperature = 19.0
t.eco_temperature = 14.0
t.target_temperature = 4.5
t.actual_temperature = 19.0
t.max_temperature = 29.0
t.min_temperature = 4.5
t.battery = 1
return t
@pytest.fixture
def windowshutter():
"""Create test MAX! window shutter."""
shutter = create_autospec(MaxWindowShutter)
shutter.name = "TestShutter"
shutter.serial = "AABBCCDD03"
shutter.rf_address = "abc3"
shutter.room_id = 1
shutter.is_open = True
shutter.is_thermostat.return_value = False
shutter.is_wallthermostat.return_value = False
shutter.is_windowshutter.return_value = True
shutter.battery = 1
return shutter
@pytest.fixture
def hass_config():
"""Return test HASS configuration."""
return {
DOMAIN: {
"gateways": [
{
"host": "1.2.3.4",
}
]
}
}
@pytest.fixture
async def cube(
hass: HomeAssistant,
hass_config: ConfigType,
room,
thermostat,
wallthermostat,
windowshutter,
):
"""Build and setup a cube mock with a single room and some devices."""
with patch("homeassistant.components.maxcube.MaxCube") as mock:
cube = mock.return_value
cube.rooms = [room]
cube.devices = [thermostat, wallthermostat, windowshutter]
cube.room_by_id.return_value = room
cube.devices_by_room.return_value = [thermostat, wallthermostat, windowshutter]
assert await async_setup_component(hass, DOMAIN, hass_config)
await hass.async_block_till_done()
gateway = hass_config[DOMAIN]["gateways"][0]
mock.assert_called_with(gateway["host"], gateway.get("port", 62910), now=now)
return cube

View File

@@ -0,0 +1,79 @@
"""Test EQ3 Max! Window Shutters."""
from datetime import timedelta
from maxcube.cube import MaxCube
from maxcube.windowshutter import MaxWindowShutter
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_FRIENDLY_NAME,
STATE_OFF,
STATE_ON,
EntityCategory,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.util import utcnow
from tests.common import async_fire_time_changed
ENTITY_ID = "binary_sensor.testroom_testshutter"
BATTERY_ENTITY_ID = f"{ENTITY_ID}_battery"
async def test_window_shuttler(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
cube: MaxCube,
windowshutter: MaxWindowShutter,
) -> None:
"""Test a successful setup with a shuttler device."""
assert entity_registry.async_is_registered(ENTITY_ID)
entity = entity_registry.async_get(ENTITY_ID)
assert entity.unique_id == "AABBCCDD03"
assert entity.entity_category == EntityCategory.DIAGNOSTIC
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.state == STATE_ON
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "TestRoom TestShutter"
assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.WINDOW
windowshutter.is_open = False
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == STATE_OFF
async def test_window_shuttler_battery(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
cube: MaxCube,
windowshutter: MaxWindowShutter,
) -> None:
"""Test battery binary_state with a shuttler device."""
assert entity_registry.async_is_registered(BATTERY_ENTITY_ID)
entity = entity_registry.async_get(BATTERY_ENTITY_ID)
assert entity.unique_id == "AABBCCDD03_battery"
assert entity.entity_category == EntityCategory.DIAGNOSTIC
state = hass.states.get(BATTERY_ENTITY_ID)
assert state is not None
assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.BATTERY
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "TestRoom TestShutter battery"
windowshutter.battery = 1 # maxcube-api MAX_DEVICE_BATTERY_LOW
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(BATTERY_ENTITY_ID)
assert state.state == STATE_ON # on means low
windowshutter.battery = 0 # maxcube-api MAX_DEVICE_BATTERY_OK
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(BATTERY_ENTITY_ID)
assert state.state == STATE_OFF # off means normal

View File

@@ -0,0 +1,432 @@
"""Test EQ3 Max! Thermostats."""
from datetime import timedelta
from maxcube.cube import MaxCube
from maxcube.device import (
MAX_DEVICE_MODE_AUTOMATIC,
MAX_DEVICE_MODE_BOOST,
MAX_DEVICE_MODE_MANUAL,
MAX_DEVICE_MODE_VACATION,
)
from maxcube.thermostat import MaxThermostat
from maxcube.wallthermostat import MaxWallThermostat
import pytest
from homeassistant.components.climate import (
ATTR_CURRENT_TEMPERATURE,
ATTR_HVAC_ACTION,
ATTR_HVAC_MODE,
ATTR_HVAC_MODES,
ATTR_MAX_TEMP,
ATTR_MIN_TEMP,
ATTR_PRESET_MODE,
ATTR_PRESET_MODES,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
DOMAIN as CLIMATE_DOMAIN,
PRESET_AWAY,
PRESET_BOOST,
PRESET_COMFORT,
PRESET_ECO,
PRESET_NONE,
SERVICE_SET_HVAC_MODE,
SERVICE_SET_PRESET_MODE,
SERVICE_SET_TEMPERATURE,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.components.maxcube.climate import (
MAX_TEMPERATURE,
MIN_TEMPERATURE,
OFF_TEMPERATURE,
ON_TEMPERATURE,
PRESET_ON,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_FRIENDLY_NAME,
ATTR_SUPPORTED_FEATURES,
ATTR_TEMPERATURE,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import entity_registry as er
from homeassistant.util import utcnow
from tests.common import async_fire_time_changed
ENTITY_ID = "climate.testroom_testthermostat"
WALL_ENTITY_ID = "climate.testroom_testwallthermostat"
VALVE_POSITION = "valve_position"
async def test_setup_thermostat(
hass: HomeAssistant, entity_registry: er.EntityRegistry, cube: MaxCube
) -> None:
"""Test a successful setup of a thermostat device."""
assert entity_registry.async_is_registered(ENTITY_ID)
entity = entity_registry.async_get(ENTITY_ID)
assert entity.unique_id == "AABBCCDD01"
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.AUTO
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "TestRoom TestThermostat"
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.HEATING
assert state.attributes.get(ATTR_HVAC_MODES) == [
HVACMode.OFF,
HVACMode.AUTO,
HVACMode.HEAT,
]
assert state.attributes.get(ATTR_PRESET_MODES) == [
PRESET_NONE,
PRESET_BOOST,
PRESET_COMFORT,
PRESET_ECO,
PRESET_AWAY,
PRESET_ON,
]
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_NONE
assert (
state.attributes.get(ATTR_SUPPORTED_FEATURES)
== ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
)
assert state.attributes.get(ATTR_MAX_TEMP) == MAX_TEMPERATURE
assert state.attributes.get(ATTR_MIN_TEMP) == 5.0
assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 19.0
assert state.attributes.get(ATTR_TEMPERATURE) == 20.5
assert state.attributes.get(VALVE_POSITION) == 25
async def test_setup_wallthermostat(
hass: HomeAssistant, entity_registry: er.EntityRegistry, cube: MaxCube
) -> None:
"""Test a successful setup of a wall thermostat device."""
assert entity_registry.async_is_registered(WALL_ENTITY_ID)
entity = entity_registry.async_get(WALL_ENTITY_ID)
assert entity.unique_id == "AABBCCDD02"
state = hass.states.get(WALL_ENTITY_ID)
assert state.state == HVACMode.OFF
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "TestRoom TestWallThermostat"
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.HEATING
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_NONE
assert state.attributes.get(ATTR_MAX_TEMP) == 29.0
assert state.attributes.get(ATTR_MIN_TEMP) == 5.0
assert state.attributes.get(ATTR_CURRENT_TEMPERATURE) == 19.0
assert state.attributes.get(ATTR_TEMPERATURE) is None
async def test_thermostat_set_hvac_mode_off(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Turn off thermostat."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.OFF},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, OFF_TEMPERATURE, MAX_DEVICE_MODE_MANUAL
)
thermostat.mode = MAX_DEVICE_MODE_MANUAL
thermostat.target_temperature = OFF_TEMPERATURE
thermostat.valve_position = 0
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.OFF
assert state.attributes.get(ATTR_TEMPERATURE) is None
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.OFF
assert state.attributes.get(VALVE_POSITION) == 0
wall_state = hass.states.get(WALL_ENTITY_ID)
assert wall_state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.OFF
async def test_thermostat_set_hvac_mode_heat(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set hvac mode to heat."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, 20.5, MAX_DEVICE_MODE_MANUAL
)
thermostat.mode = MAX_DEVICE_MODE_MANUAL
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.HEAT
async def test_thermostat_set_invalid_hvac_mode(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set hvac mode to heat."""
with pytest.raises(ValueError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_HVAC_MODE: HVACMode.DRY},
blocking=True,
)
cube.set_temperature_mode.assert_not_called()
async def test_thermostat_set_temperature(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set hvac mode to heat."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 10.0},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(thermostat, 10.0, None)
thermostat.target_temperature = 10.0
thermostat.valve_position = 0
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.AUTO
assert state.attributes.get(ATTR_TEMPERATURE) == 10.0
assert state.attributes.get(ATTR_HVAC_ACTION) == HVACAction.IDLE
async def test_thermostat_set_no_temperature(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set hvac mode to heat."""
with pytest.raises(ServiceValidationError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_TARGET_TEMP_HIGH: 29.0,
ATTR_TARGET_TEMP_LOW: 10.0,
},
blocking=True,
)
cube.set_temperature_mode.assert_not_called()
async def test_thermostat_set_preset_on(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set preset mode to on."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_ON},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, ON_TEMPERATURE, MAX_DEVICE_MODE_MANUAL
)
thermostat.mode = MAX_DEVICE_MODE_MANUAL
thermostat.target_temperature = ON_TEMPERATURE
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.HEAT
assert state.attributes.get(ATTR_TEMPERATURE) is None
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_ON
async def test_thermostat_set_preset_comfort(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set preset mode to comfort."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_COMFORT},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, thermostat.comfort_temperature, MAX_DEVICE_MODE_MANUAL
)
thermostat.mode = MAX_DEVICE_MODE_MANUAL
thermostat.target_temperature = thermostat.comfort_temperature
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.HEAT
assert state.attributes.get(ATTR_TEMPERATURE) == thermostat.comfort_temperature
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_COMFORT
async def test_thermostat_set_preset_eco(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set preset mode to eco."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_ECO},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, thermostat.eco_temperature, MAX_DEVICE_MODE_MANUAL
)
thermostat.mode = MAX_DEVICE_MODE_MANUAL
thermostat.target_temperature = thermostat.eco_temperature
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.HEAT
assert state.attributes.get(ATTR_TEMPERATURE) == thermostat.eco_temperature
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_ECO
async def test_thermostat_set_preset_away(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set preset mode to away."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_AWAY},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, None, MAX_DEVICE_MODE_VACATION
)
thermostat.mode = MAX_DEVICE_MODE_VACATION
thermostat.target_temperature = thermostat.eco_temperature
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.HEAT
assert state.attributes.get(ATTR_TEMPERATURE) == thermostat.eco_temperature
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_AWAY
async def test_thermostat_set_preset_boost(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set preset mode to boost."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_BOOST},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, None, MAX_DEVICE_MODE_BOOST
)
thermostat.mode = MAX_DEVICE_MODE_BOOST
thermostat.target_temperature = thermostat.eco_temperature
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(ENTITY_ID)
assert state.state == HVACMode.AUTO
assert state.attributes.get(ATTR_TEMPERATURE) == thermostat.eco_temperature
assert state.attributes.get(ATTR_PRESET_MODE) == PRESET_BOOST
async def test_thermostat_set_preset_none(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set preset mode to boost."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: PRESET_NONE},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
thermostat, None, MAX_DEVICE_MODE_AUTOMATIC
)
async def test_thermostat_set_invalid_preset(
hass: HomeAssistant, cube: MaxCube, thermostat: MaxThermostat
) -> None:
"""Set hvac mode to heat."""
with pytest.raises(ServiceValidationError):
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_PRESET_MODE,
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_PRESET_MODE: "invalid"},
blocking=True,
)
cube.set_temperature_mode.assert_not_called()
async def test_wallthermostat_set_hvac_mode_heat(
hass: HomeAssistant, cube: MaxCube, wallthermostat: MaxWallThermostat
) -> None:
"""Set wall thermostat hvac mode to heat."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: WALL_ENTITY_ID, ATTR_HVAC_MODE: HVACMode.HEAT},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
wallthermostat, MIN_TEMPERATURE, MAX_DEVICE_MODE_MANUAL
)
wallthermostat.target_temperature = MIN_TEMPERATURE
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(WALL_ENTITY_ID)
assert state.state == HVACMode.HEAT
assert state.attributes.get(ATTR_TEMPERATURE) == MIN_TEMPERATURE
async def test_wallthermostat_set_hvac_mode_auto(
hass: HomeAssistant, cube: MaxCube, wallthermostat: MaxWallThermostat
) -> None:
"""Set wall thermostat hvac mode to auto."""
await hass.services.async_call(
CLIMATE_DOMAIN,
SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: WALL_ENTITY_ID, ATTR_HVAC_MODE: HVACMode.AUTO},
blocking=True,
)
cube.set_temperature_mode.assert_called_once_with(
wallthermostat, None, MAX_DEVICE_MODE_AUTOMATIC
)
wallthermostat.mode = MAX_DEVICE_MODE_AUTOMATIC
wallthermostat.target_temperature = 23.0
async_fire_time_changed(hass, utcnow() + timedelta(minutes=5))
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get(WALL_ENTITY_ID)
assert state.state == HVACMode.AUTO
assert state.attributes.get(ATTR_TEMPERATURE) == 23.0