Skip to content

Instantly share code, notes, and snippets.

@CoMPaTech
Created May 30, 2020 09:25
Show Gist options
  • Save CoMPaTech/c682558d705cd094460d0271182c2ab5 to your computer and use it in GitHub Desktop.
Save CoMPaTech/c682558d705cd094460d0271182c2ab5 to your computer and use it in GitHub Desktop.
HA testing for plugwise
"""Tests for the tado integration."""
from homeassistant.components.plugwise import DOMAIN
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
import pytest
import re
@pytest.fixture(name="mock_smile_adam")
def mock_smile_adam(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock the DirecTV connection for Home Assistant."""
url = "http://1.1.1.1:80/core/"
fixturepath = "plugwise/adam_multiple_devices_per_zone/"
aioclient_mock.get(url + "domain_objects", text=load_fixture(fixturepath + "core.domain_objects.xml"))
aioclient_mock.get(url + "direct_objects", text=load_fixture(fixturepath + "core.direct_objects.xml"))
aioclient_mock.get(url + "appliances", text=load_fixture(fixturepath + "core.appliances.xml"))
aioclient_mock.get(url + "modules", text=load_fixture(fixturepath + "core.modules.xml"))
aioclient_mock.get(url + "locations", text=load_fixture(fixturepath + "core.locations.xml"))
aioclient_mock.put(re.compile(f"{url}locations.*"), text="<xml />", status=202)
@pytest.fixture(name="mock_smile_anna")
def mock_smile_anna(aioclient_mock: AiohttpClientMocker) -> None:
"""Mock the DirecTV connection for Home Assistant."""
url = "http://1.1.1.1:80/core/"
fixturepath = "plugwise/anna_heatpump/"
aioclient_mock.get(url + "domain_objects", text=load_fixture(fixturepath + "core.domain_objects.xml"))
aioclient_mock.get(url + "direct_objects", text=load_fixture(fixturepath + "core.direct_objects.xml"))
aioclient_mock.get(url + "appliances", text=load_fixture(fixturepath + "core.appliances.xml"))
aioclient_mock.get(url + "modules", text=load_fixture(fixturepath + "core.modules.xml"))
aioclient_mock.get(url + "locations", text=load_fixture(fixturepath + "core.locations.xml"))
aioclient_mock.put(re.compile(f"{url}locations.*"), text="<xml />", status=202)
async def async_init_integration(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, skip_setup: bool = False,
):
"""Initialize the Smile integration."""
entry = MockConfigEntry(
domain=DOMAIN, data={"host": "1.1.1.1", "password": "test-password"}
)
entry.add_to_hass(hass)
if not skip_setup:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
async def test_adam_climate_entity(hass, mock_smile_adam):
"""Test creation of anna climate entity."""
await async_init_integration(hass, mock_smile_adam)
state = hass.states.get("climate.zone_lisa_wk")
attrs = state.attributes
assert attrs["hvac_modes"] is None
assert "preset_modes" in attrs
assert "no_frost" in attrs["preset_modes"]
assert "home" in attrs["preset_modes"]
assert attrs["current_temperature"] == 20.9
assert attrs["temperature"] == 21.5
assert attrs["preset_mode"] == "home"
assert attrs["supported_features"] == 17
await hass.services.async_call(
"climate", "set_temperature", {"entity_id": "climate.zone_lisa_wk", "temperature": 25}, blocking=True
)
state = hass.states.get("climate.zone_lisa_wk")
attrs = state.attributes
assert attrs["temperature"] == 25.0
state = hass.states.get("climate.zone_thermostat_jessie")
attrs = state.attributes
assert attrs["hvac_modes"] is None
assert "preset_modes" in attrs
assert "no_frost" in attrs["preset_modes"]
assert "home" in attrs["preset_modes"]
assert attrs["current_temperature"] == 17.2
assert attrs["temperature"] == 15.0
assert attrs["preset_mode"] == "asleep"
assert attrs["supported_features"] == 17
await hass.services.async_call(
"climate", "set_temperature", {"entity_id": "climate.zone_thermostat_jessie", "temperature": 25}, blocking=True
)
state = hass.states.get("climate.zone_thermostat_jessie")
attrs = state.attributes
assert attrs["temperature"] == 25.0
async def test_adam_climate_sensor_entities(hass, mock_smile_adam):
"""Test creation of climate and sensor entities."""
await async_init_integration(hass, mock_smile_adam)
state = hass.states.get("sensor.adam_outdoor_temperature")
assert float(state.state) == 7.8
state = hass.states.get("sensor.zone_lisa_wk_battery")
assert float(state.state) == 34
state = hass.states.get("sensor.cv_pomp_electricity_consumed")
assert float(state.state) == 35.6
state = hass.states.get("sensor.auxiliary_water_temperature")
assert float(state.state) == 70.0
state = hass.states.get("sensor.cv_pomp_electricity_consumed_interval")
assert float(state.state) == 7.37
async def test_anna_climate_entity(hass, mock_smile_anna):
"""Test creation of anna climate entity."""
await async_init_integration(hass, mock_smile_anna)
state = hass.states.get("climate.anna")
attrs = state.attributes
assert "hvac_modes" in attrs
assert "heat_cool" in attrs["hvac_modes"]
assert "preset_modes" in attrs
assert "no_frost" in attrs["preset_modes"]
assert "home" in attrs["preset_modes"]
assert attrs["current_temperature"] == 23.3
assert attrs["temperature"] == 21.0
assert attrs["hvac_action"] == "idle"
assert attrs["preset_mode"] == "home"
assert attrs["supported_features"] == 17
await hass.services.async_call(
"climate", "set_temperature", {"entity_id": "climate.anna", "temperature": 25}, blocking=True
)
state = hass.states.get("climate.anna")
attrs = state.attributes
assert attrs["temperature"] == 25.0
async def test_anna_climate_sensor_entities(hass, mock_smile_anna):
"""Test creation of climate and sensor entities."""
await async_init_integration(hass, mock_smile_anna)
state = hass.states.get("sensor.auxiliary_outdoor_temperature")
assert float(state.state) == 18.0
state = hass.states.get("sensor.auxiliary_water_temperature")
assert float(state.state) == 29.1
state = hass.states.get("sensor.anna_illuminance")
assert float(state.state) == 86.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment