Add tests to honeywell (#87209)

* lower case aiosomecomfort

* add tests

* Test updates for 0.0.6

* lower case aiosomecomfort

* Missing changes after merge

* Add missing type hints

* Fix tests for PR#89393

* Test hold on when setting temperature

* Remove unnecessary init function

* Remove unnecessary assert

* Address missing tests
Cleanup related to comments for EM

* Move to snapshot for static test

* Updated snapshot

* Remove unnecessary assert
This commit is contained in:
mkmer 2023-04-12 14:34:32 -04:00 committed by GitHub
parent e36fd5f222
commit 6aa1460143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1236 additions and 30 deletions

View File

@ -480,8 +480,6 @@ omit =
homeassistant/components/homematic/sensor.py
homeassistant/components/homematic/switch.py
homeassistant/components/homeworks/*
homeassistant/components/honeywell/__init__.py
homeassistant/components/honeywell/climate.py
homeassistant/components/horizon/media_player.py
homeassistant/components/hp_ilo/sensor.py
homeassistant/components/huawei_lte/__init__.py

View File

@ -214,9 +214,9 @@ class HoneywellUSThermostat(ClimateEntity):
return self._device.current_humidity
@property
def hvac_mode(self) -> HVACMode:
def hvac_mode(self) -> HVACMode | None:
"""Return hvac operation ie. heat, cool mode."""
return HW_MODE_TO_HVAC_MODE[self._device.system_mode]
return HW_MODE_TO_HVAC_MODE.get(self._device.system_mode)
@property
def hvac_action(self) -> HVACAction | None:
@ -343,12 +343,8 @@ class HoneywellUSThermostat(ClimateEntity):
it doesn't get overwritten when away mode is switched on.
"""
self._away = True
try:
# Get current mode
mode = self._device.system_mode
except aiosomecomfort.SomeComfortError:
_LOGGER.error("Can not get system mode")
return
# Get current mode
mode = self._device.system_mode
try:
# Set permanent hold
# and Set temperature
@ -367,12 +363,8 @@ class HoneywellUSThermostat(ClimateEntity):
async def _turn_hold_mode_on(self) -> None:
"""Turn permanent hold on."""
try:
# Get current mode
mode = self._device.system_mode
except aiosomecomfort.SomeComfortError:
_LOGGER.error("Can not get system mode")
return
# Get current mode
mode = self._device.system_mode
# Check that we got a valid mode back
if mode in HW_MODE_TO_HVAC_MODE:
try:

View File

@ -1 +1,25 @@
"""Tests for honeywell component."""
from unittest.mock import MagicMock
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
async def init_integration(
hass: HomeAssistant, entry: MockConfigEntry
) -> MockConfigEntry:
"""Set up the Honeywell integration in Home Assistant."""
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry
def reset_mock(device: MagicMock) -> None:
"""Reset the mocks for test."""
device.set_setpoint_cool.reset_mock()
device.set_setpoint_heat.reset_mock()
device.set_hold_heat.reset_mock()
device.set_hold_cool.reset_mock()

View File

@ -5,25 +5,53 @@ from unittest.mock import AsyncMock, create_autospec, patch
import aiosomecomfort
import pytest
from homeassistant.components.honeywell.const import DOMAIN
from homeassistant.components.honeywell.const import (
CONF_COOL_AWAY_TEMPERATURE,
CONF_HEAT_AWAY_TEMPERATURE,
DOMAIN,
)
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from tests.common import MockConfigEntry
HEATUPPERSETPOINTLIMIT = 35
HEATLOWERSETPOINTLIMIT = 20
COOLUPPERSETPOINTLIMIT = 20
COOLLOWERSETPOINTLIMIT = 10
NEXTCOOLPERIOD = 10
NEXTHEATPERIOD = 10
OUTDOORTEMP = 5
OUTDOORHUMIDITY = 25
CURRENTTEMPERATURE = 20
CURRENTHUMIDITY = 50
HEATAWAY = 10
COOLAWAY = 20
SETPOINTCOOL = 26
SETPOINTHEAT = 18
@pytest.fixture
def config_data():
"""Provide configuration data for tests."""
return {CONF_USERNAME: "fake", CONF_PASSWORD: "user"}
return {
CONF_USERNAME: "fake",
CONF_PASSWORD: "user",
}
@pytest.fixture
def config_entry(config_data):
def config_options():
"""Provide configuratio options for test."""
return {CONF_COOL_AWAY_TEMPERATURE: 12, CONF_HEAT_AWAY_TEMPERATURE: 22}
@pytest.fixture
def config_entry(config_data, config_options):
"""Create a mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
data=config_data,
options={},
options=config_options,
)
@ -33,15 +61,53 @@ def device():
mock_device = create_autospec(aiosomecomfort.device.Device, instance=True)
mock_device.deviceid = 1234567
mock_device._data = {
"canControlHumidification": False,
"hasFan": False,
"canControlHumidification": True,
"hasFan": True,
}
mock_device.system_mode = "off"
mock_device.name = "device1"
mock_device.current_temperature = 20
mock_device.current_temperature = CURRENTTEMPERATURE
mock_device.mac_address = "macaddress1"
mock_device.outdoor_temperature = None
mock_device.outdoor_humidity = None
mock_device.is_alive = True
mock_device.fan_running = False
mock_device.fan_mode = "auto"
mock_device.setpoint_cool = SETPOINTCOOL
mock_device.setpoint_heat = SETPOINTHEAT
mock_device.hold_heat = False
mock_device.hold_cool = False
mock_device.current_humidity = CURRENTHUMIDITY
mock_device.equipment_status = "off"
mock_device.equipment_output_status = "off"
mock_device.raw_ui_data = {
"SwitchOffAllowed": True,
"SwitchAutoAllowed": True,
"SwitchCoolAllowed": True,
"SwitchHeatAllowed": True,
"SwitchEmergencyHeatAllowed": True,
"HeatUpperSetptLimit": HEATUPPERSETPOINTLIMIT,
"HeatLowerSetptLimit": HEATLOWERSETPOINTLIMIT,
"CoolUpperSetptLimit": COOLUPPERSETPOINTLIMIT,
"CoolLowerSetptLimit": COOLLOWERSETPOINTLIMIT,
"HeatNextPeriod": NEXTHEATPERIOD,
"CoolNextPeriod": NEXTCOOLPERIOD,
}
mock_device.raw_fan_data = {
"fanModeOnAllowed": True,
"fanModeAutoAllowed": True,
"fanModeCirculateAllowed": True,
}
mock_device.set_setpoint_cool = AsyncMock()
mock_device.set_setpoint_heat = AsyncMock()
mock_device.set_system_mode = AsyncMock()
mock_device.set_fan_mode = AsyncMock()
mock_device.set_hold_heat = AsyncMock()
mock_device.set_hold_cool = AsyncMock()
mock_device.refresh = AsyncMock()
mock_device.heat_away_temp = HEATAWAY
mock_device.cool_away_temp = COOLAWAY
return mock_device
@ -56,11 +122,11 @@ def device_with_outdoor_sensor():
}
mock_device.system_mode = "off"
mock_device.name = "device1"
mock_device.current_temperature = 20
mock_device.current_temperature = CURRENTTEMPERATURE
mock_device.mac_address = "macaddress1"
mock_device.temperature_unit = "C"
mock_device.outdoor_temperature = 5
mock_device.outdoor_humidity = 25
mock_device.outdoor_temperature = OUTDOORTEMP
mock_device.outdoor_humidity = OUTDOORHUMIDITY
return mock_device
@ -75,7 +141,7 @@ def another_device():
}
mock_device.system_mode = "off"
mock_device.name = "device2"
mock_device.current_temperature = 20
mock_device.current_temperature = CURRENTTEMPERATURE
mock_device.mac_address = "macaddress1"
mock_device.outdoor_temperature = None
mock_device.outdoor_humidity = None

View File

@ -0,0 +1,38 @@
# serializer version: 1
# name: test_static_attributes
ReadOnlyDict({
'aux_heat': 'off',
'current_humidity': 50,
'current_temperature': -6.7,
'fan_action': 'idle',
'fan_mode': 'auto',
'fan_modes': list([
'on',
'auto',
'diffuse',
]),
'friendly_name': 'device1',
'humidity': None,
'hvac_modes': list([
<HVACMode.OFF: 'off'>,
<HVACMode.HEAT_COOL: 'heat_cool'>,
<HVACMode.COOL: 'cool'>,
<HVACMode.HEAT: 'heat'>,
]),
'max_humidity': 99,
'max_temp': 1.7,
'min_humidity': 30,
'min_temp': -13.9,
'permanent_hold': False,
'preset_mode': None,
'preset_modes': list([
'none',
'away',
'Hold',
]),
'supported_features': <ClimateEntityFeature: 95>,
'target_temp_high': None,
'target_temp_low': None,
'temperature': None,
})
# ---

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
"""Test honeywell setup process."""
from unittest.mock import create_autospec, patch
from unittest.mock import MagicMock, create_autospec, patch
import aiosomecomfort
import pytest
@ -13,6 +13,8 @@ from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from . import init_integration
from tests.common import MockConfigEntry
MIGRATE_OPTIONS_KEYS = {CONF_COOL_AWAY_TEMPERATURE, CONF_HEAT_AWAY_TEMPERATURE}
@ -28,7 +30,6 @@ async def test_setup_entry(hass: HomeAssistant, config_entry: MockConfigEntry) -
assert hass.states.async_entity_ids_count() == 1
@patch("homeassistant.components.honeywell.UPDATE_LOOP_SLEEP_TIME", 0)
async def test_setup_multiple_thermostats(
hass: HomeAssistant, config_entry: MockConfigEntry, location, another_device
) -> None:
@ -41,7 +42,6 @@ async def test_setup_multiple_thermostats(
assert hass.states.async_entity_ids_count() == 2
@patch("homeassistant.components.honeywell.UPDATE_LOOP_SLEEP_TIME", 0)
async def test_setup_multiple_thermostats_with_same_deviceid(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
@ -82,3 +82,30 @@ async def test_away_temps_migration(hass: HomeAssistant) -> None:
CONF_COOL_AWAY_TEMPERATURE: 1,
CONF_HEAT_AWAY_TEMPERATURE: 2,
}
async def test_login_error(
hass: HomeAssistant, client: MagicMock, config_entry: MagicMock
) -> None:
"""Test login errors from API."""
client.login.side_effect = aiosomecomfort.AuthError
await init_integration(hass, config_entry)
assert config_entry.state is ConfigEntryState.SETUP_ERROR
async def test_connection_error(
hass: HomeAssistant, client: MagicMock, config_entry: MagicMock
) -> None:
"""Test Connection errors from API."""
client.login.side_effect = aiosomecomfort.ConnectionError
await init_integration(hass, config_entry)
assert config_entry.state is ConfigEntryState.SETUP_RETRY
async def test_no_devices(
hass: HomeAssistant, client: MagicMock, config_entry: MagicMock
) -> None:
"""Test no devices from API."""
client.locations_by_id = {}
await init_integration(hass, config_entry)
assert config_entry.state is ConfigEntryState.SETUP_ERROR