Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to honeywell #87209

Merged
merged 19 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,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
Expand Down
20 changes: 6 additions & 14 deletions homeassistant/components/honeywell/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ def current_humidity(self) -> int | None:
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:
Expand Down Expand Up @@ -341,12 +341,8 @@ async def _turn_away_mode_on(self) -> None:
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
Expand All @@ -365,12 +361,8 @@ async def _turn_away_mode_on(self) -> None:

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:
Expand Down
24 changes: 24 additions & 0 deletions tests/components/honeywell/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
88 changes: 77 additions & 11 deletions tests/components/honeywell/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,53 @@
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_options():
"""Provide configuratio options for test."""
return {CONF_COOL_AWAY_TEMPERATURE: 12, CONF_HEAT_AWAY_TEMPERATURE: 22}


@pytest.fixture
def config_entry(config_data):
def config_entry(config_data, config_options):
"""Create a mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
data=config_data,
options={},
options=config_options,
)


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions tests/components/honeywell/snapshots/test_climate.ambr
Original file line number Diff line number Diff line change
@@ -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,
})
# ---
Loading