Clean dyson climate tests (#40110)

* Move setup without devices

* Remove not needed tests

* Move set temp test

* Move set temp cool mode test

* Run black

* Move test target temperature

* Move test current temperature

* Move test current humidity

* Move test hvac mode

* Move test hvac modes

* Move test fan modes

* Move test service fan modes

* Move test fan state

* Move test supported features

* Move test idle state

* Move test humidity invalid state

* Move test humidity without state

* Move test device cool

* Rename test

* Move test set mode service

* Clean imports

* Clean strings

* Only load climate platform for climate tests
This commit is contained in:
Martin Hjelmare 2020-09-15 22:38:45 +02:00 committed by GitHub
parent f651b1f54b
commit a71a4d642b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
"""Test the Dyson fan component.""" """Test the Dyson fan component."""
import json import json
import unittest
from libpurecool.const import ( from libpurecool.const import (
FanPower, FanPower,
@ -15,8 +14,8 @@ from libpurecool.dyson_pure_hotcool import DysonPureHotCool
from libpurecool.dyson_pure_hotcool_link import DysonPureHotCoolLink from libpurecool.dyson_pure_hotcool_link import DysonPureHotCoolLink
from libpurecool.dyson_pure_state import DysonPureHotCoolState from libpurecool.dyson_pure_state import DysonPureHotCoolState
from libpurecool.dyson_pure_state_v2 import DysonPureHotCoolV2State from libpurecool.dyson_pure_state_v2 import DysonPureHotCoolV2State
import pytest
from homeassistant.components import dyson as dyson_parent
from homeassistant.components.climate import ( from homeassistant.components.climate import (
DOMAIN, DOMAIN,
SERVICE_SET_FAN_MODE, SERVICE_SET_FAN_MODE,
@ -25,9 +24,16 @@ from homeassistant.components.climate import (
) )
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
ATTR_CURRENT_HUMIDITY, ATTR_CURRENT_HUMIDITY,
ATTR_CURRENT_TEMPERATURE,
ATTR_FAN_MODE, ATTR_FAN_MODE,
ATTR_FAN_MODES,
ATTR_HVAC_ACTION, ATTR_HVAC_ACTION,
ATTR_HVAC_MODE, ATTR_HVAC_MODE,
ATTR_HVAC_MODES,
ATTR_MAX_TEMP,
ATTR_MIN_TEMP,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
CURRENT_HVAC_COOL, CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT, CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE, CURRENT_HVAC_IDLE,
@ -40,19 +46,29 @@ from homeassistant.components.climate.const import (
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
HVAC_MODE_OFF, HVAC_MODE_OFF,
) )
from homeassistant.components.dyson import climate as dyson from homeassistant.components.dyson import CONF_LANGUAGE, DOMAIN as DYSON_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.components.dyson.climate import FAN_DIFFUSE, FAN_FOCUS, SUPPORT_FLAGS
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
ATTR_TEMPERATURE,
CONF_DEVICES,
CONF_PASSWORD,
CONF_USERNAME,
TEMP_CELSIUS,
)
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from .common import load_mock_device from .common import load_mock_device
from tests.async_mock import MagicMock, Mock, patch from tests.async_mock import Mock, call, patch
from tests.common import get_test_home_assistant
class MockDysonState(DysonPureHotCoolState): class MockDysonState(DysonPureHotCoolState):
"""Mock Dyson state.""" """Mock Dyson state."""
# pylint: disable=super-init-not-called
def __init__(self): def __init__(self):
"""Create new Mock Dyson State.""" """Create new Mock Dyson State."""
@ -64,11 +80,11 @@ class MockDysonState(DysonPureHotCoolState):
def _get_config(): def _get_config():
"""Return a config dictionary.""" """Return a config dictionary."""
return { return {
dyson_parent.DOMAIN: { DYSON_DOMAIN: {
dyson_parent.CONF_USERNAME: "email", CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password", CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "GB", CONF_LANGUAGE: "GB",
dyson_parent.CONF_DEVICES: [ CONF_DEVICES: [
{"device_id": "XX-XXXXX-XX", "device_ip": "192.168.0.1"}, {"device_id": "XX-XXXXX-XX", "device_ip": "192.168.0.1"},
{"device_id": "YY-YYYYY-YY", "device_ip": "192.168.0.2"}, {"device_id": "YY-YYYYY-YY", "device_ip": "192.168.0.2"},
], ],
@ -89,15 +105,6 @@ def _get_dyson_purehotcool_device():
return device return device
def _get_device_with_no_state():
"""Return a device with no state."""
device = Mock(spec=DysonPureHotCoolLink)
load_mock_device(device)
device.state = None
device.environmental_state = None
return device
def _get_device_off(): def _get_device_off():
"""Return a device with state off.""" """Return a device with state off."""
device = Mock(spec=DysonPureHotCoolLink) device = Mock(spec=DysonPureHotCoolLink)
@ -105,22 +112,6 @@ def _get_device_off():
return device return device
def _get_device_focus():
"""Return a device with fan state of focus mode."""
device = Mock(spec=DysonPureHotCoolLink)
load_mock_device(device)
device.state.focus_mode = FocusMode.FOCUS_ON.value
return device
def _get_device_diffuse():
"""Return a device with fan state of diffuse mode."""
device = Mock(spec=DysonPureHotCoolLink)
load_mock_device(device)
device.state.focus_mode = FocusMode.FOCUS_OFF.value
return device
def _get_device_cool(): def _get_device_cool():
"""Return a device with state of cooling.""" """Return a device with state of cooling."""
device = Mock(spec=DysonPureHotCoolLink) device = Mock(spec=DysonPureHotCoolLink)
@ -132,15 +123,6 @@ def _get_device_cool():
return device return device
def _get_device_heat_off():
"""Return a device with state of heat reached target."""
device = Mock(spec=DysonPureHotCoolLink)
load_mock_device(device)
device.state.heat_mode = HeatMode.HEAT_ON.value
device.state.heat_state = HeatState.HEAT_STATE_OFF.value
return device
def _get_device_heat_on(): def _get_device_heat_on():
"""Return a device with state of heating.""" """Return a device with state of heating."""
device = Mock(spec=DysonPureHotCoolLink) device = Mock(spec=DysonPureHotCoolLink)
@ -154,236 +136,259 @@ def _get_device_heat_on():
return device return device
class DysonTest(unittest.TestCase): @pytest.fixture(autouse=True)
"""Dyson Climate component test class.""" def patch_platforms_fixture():
"""Only set up the climate platform for the climate tests."""
with patch("homeassistant.components.dyson.DYSON_PLATFORMS", new=[DOMAIN]):
yield
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup)
def tear_down_cleanup(self): @patch(
"""Stop everything that was started.""" "homeassistant.components.dyson.DysonAccount.devices",
self.hass.stop() return_value=[_get_device_heat_on()],
)
@patch("homeassistant.components.dyson.DysonAccount.login", return_value=True)
async def test_pure_hot_cool_link_set_mode(mocked_login, mocked_devices, hass):
"""Test set climate mode."""
await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
def test_setup_component_without_devices(self): device = mocked_devices.return_value[0]
"""Test setup component with no devices."""
self.hass.data[dyson.DYSON_DEVICES] = []
add_devices = MagicMock()
dyson.setup_platform(self.hass, None, add_devices)
add_devices.assert_not_called()
def test_setup_component_with_devices(self): await hass.services.async_call(
"""Test setup component with valid devices.""" DOMAIN,
devices = [ SERVICE_SET_HVAC_MODE,
_get_device_with_no_state(), {ATTR_ENTITY_ID: "climate.temp_name", ATTR_HVAC_MODE: HVAC_MODE_HEAT},
_get_device_off(), True,
_get_device_heat_on(), )
]
self.hass.data[dyson.DYSON_DEVICES] = devices
add_devices = MagicMock()
dyson.setup_platform(self.hass, None, add_devices, discovery_info={})
assert add_devices.called
def test_setup_component(self): set_config = device.set_configuration
"""Test setup component with devices.""" assert set_config.call_args == call(heat_mode=HeatMode.HEAT_ON)
device_fan = _get_device_heat_on()
device_non_fan = _get_device_off()
def _add_device(devices): await hass.services.async_call(
assert len(devices) == 1 DOMAIN,
assert devices[0].name == "Device_name" SERVICE_SET_HVAC_MODE,
{ATTR_ENTITY_ID: "climate.temp_name", ATTR_HVAC_MODE: HVAC_MODE_COOL},
True,
)
self.hass.data[dyson.DYSON_DEVICES] = [device_fan, device_non_fan] set_config = device.set_configuration
dyson.setup_platform(self.hass, None, _add_device) assert set_config.call_args == call(heat_mode=HeatMode.HEAT_OFF)
def test_dyson_set_temperature(self):
"""Test set climate temperature."""
device = _get_device_heat_on()
device.temp_unit = TEMP_CELSIUS
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert not entity.should_poll
# Without target temp. @patch(
kwargs = {} "homeassistant.components.dyson.DysonAccount.devices",
entity.set_temperature(**kwargs) return_value=[_get_device_heat_on()],
set_config = device.set_configuration )
set_config.assert_not_called() @patch("homeassistant.components.dyson.DysonAccount.login", return_value=True)
async def test_pure_hot_cool_link_set_fan(mocked_login, mocked_devices, hass):
"""Test set climate fan."""
await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
kwargs = {ATTR_TEMPERATURE: 23} device = mocked_devices.return_value[0]
entity.set_temperature(**kwargs) device.temp_unit = TEMP_CELSIUS
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23)
)
# Should clip the target temperature between 1 and 37 inclusive. await hass.services.async_call(
kwargs = {ATTR_TEMPERATURE: 50} DOMAIN,
entity.set_temperature(**kwargs) SERVICE_SET_FAN_MODE,
set_config = device.set_configuration {ATTR_ENTITY_ID: "climate.temp_name", ATTR_FAN_MODE: FAN_FOCUS},
set_config.assert_called_with( True,
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(37) )
)
kwargs = {ATTR_TEMPERATURE: -5} set_config = device.set_configuration
entity.set_temperature(**kwargs) assert set_config.call_args == call(focus_mode=FocusMode.FOCUS_ON)
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(1)
)
def test_dyson_set_temperature_when_cooling_mode(self): await hass.services.async_call(
"""Test set climate temperature when heating is off.""" DOMAIN,
device = _get_device_cool() SERVICE_SET_FAN_MODE,
device.temp_unit = TEMP_CELSIUS {ATTR_ENTITY_ID: "climate.temp_name", ATTR_FAN_MODE: FAN_DIFFUSE},
entity = dyson.DysonPureHotCoolLinkEntity(device) True,
entity.schedule_update_ha_state = Mock() )
kwargs = {ATTR_TEMPERATURE: 23} set_config = device.set_configuration
entity.set_temperature(**kwargs) assert set_config.call_args == call(focus_mode=FocusMode.FOCUS_OFF)
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23)
)
def test_dyson_set_fan_mode(self):
"""Test set fan mode."""
device = _get_device_heat_on()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert not entity.should_poll
entity.set_fan_mode(dyson.FAN_FOCUS) @patch(
set_config = device.set_configuration "homeassistant.components.dyson.DysonAccount.devices",
set_config.assert_called_with(focus_mode=FocusMode.FOCUS_ON) return_value=[_get_device_heat_on()],
)
@patch("homeassistant.components.dyson.DysonAccount.login", return_value=True)
async def test_pure_hot_cool_link_state(mocked_login, mocked_devices, hass):
"""Test set climate temperature."""
await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
entity.set_fan_mode(dyson.FAN_DIFFUSE) state = hass.states.get("climate.temp_name")
set_config = device.set_configuration assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_FLAGS
set_config.assert_called_with(focus_mode=FocusMode.FOCUS_OFF) assert state.attributes[ATTR_TEMPERATURE] == 23
assert state.attributes[ATTR_CURRENT_TEMPERATURE] == 289 - 273
assert state.attributes[ATTR_CURRENT_HUMIDITY] == 53
assert state.state == HVAC_MODE_HEAT
assert len(state.attributes[ATTR_HVAC_MODES]) == 2
assert HVAC_MODE_HEAT in state.attributes[ATTR_HVAC_MODES]
assert HVAC_MODE_COOL in state.attributes[ATTR_HVAC_MODES]
assert len(state.attributes[ATTR_FAN_MODES]) == 2
assert FAN_FOCUS in state.attributes[ATTR_FAN_MODES]
assert FAN_DIFFUSE in state.attributes[ATTR_FAN_MODES]
def test_dyson_fan_modes(self): device = mocked_devices.return_value[0]
"""Test get fan list.""" update_callback = device.add_message_listener.call_args[0][0]
device = _get_device_heat_on()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert len(entity.fan_modes) == 2
assert dyson.FAN_FOCUS in entity.fan_modes
assert dyson.FAN_DIFFUSE in entity.fan_modes
def test_dyson_fan_mode_focus(self): device.state.focus_mode = FocusMode.FOCUS_ON.value
"""Test fan focus mode.""" await hass.async_add_executor_job(update_callback, MockDysonState())
device = _get_device_focus() await hass.async_block_till_done()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.fan_mode == dyson.FAN_FOCUS
def test_dyson_fan_mode_diffuse(self): state = hass.states.get("climate.temp_name")
"""Test fan diffuse mode.""" assert state.attributes[ATTR_FAN_MODE] == FAN_FOCUS
device = _get_device_diffuse()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.fan_mode == dyson.FAN_DIFFUSE
def test_dyson_set_hvac_mode(self): device.state.focus_mode = FocusMode.FOCUS_OFF.value
"""Test set operation mode.""" await hass.async_add_executor_job(update_callback, MockDysonState())
device = _get_device_heat_on() await hass.async_block_till_done()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert not entity.should_poll
entity.set_hvac_mode(dyson.HVAC_MODE_HEAT) state = hass.states.get("climate.temp_name")
set_config = device.set_configuration assert state.attributes[ATTR_FAN_MODE] == FAN_DIFFUSE
set_config.assert_called_with(heat_mode=HeatMode.HEAT_ON)
entity.set_hvac_mode(dyson.HVAC_MODE_COOL) device.state.heat_mode = HeatMode.HEAT_ON.value
set_config = device.set_configuration device.state.heat_state = HeatState.HEAT_STATE_OFF.value
set_config.assert_called_with(heat_mode=HeatMode.HEAT_OFF) await hass.async_add_executor_job(update_callback, MockDysonState())
await hass.async_block_till_done()
def test_dyson_operation_list(self): state = hass.states.get("climate.temp_name")
"""Test get operation list.""" assert state.state == HVAC_MODE_HEAT
device = _get_device_heat_on() assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_IDLE
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert len(entity.hvac_modes) == 2
assert dyson.HVAC_MODE_HEAT in entity.hvac_modes
assert dyson.HVAC_MODE_COOL in entity.hvac_modes
def test_dyson_heat_off(self): device.environmental_state.humidity = 0
"""Test turn off heat.""" await hass.async_add_executor_job(update_callback, MockDysonState())
device = _get_device_heat_off() await hass.async_block_till_done()
entity = dyson.DysonPureHotCoolLinkEntity(device)
entity.set_hvac_mode(dyson.HVAC_MODE_COOL)
set_config = device.set_configuration
set_config.assert_called_with(heat_mode=HeatMode.HEAT_OFF)
def test_dyson_heat_on(self): state = hass.states.get("climate.temp_name")
"""Test turn on heat.""" assert state.attributes.get(ATTR_CURRENT_HUMIDITY) is None
device = _get_device_heat_on()
entity = dyson.DysonPureHotCoolLinkEntity(device)
entity.set_hvac_mode(dyson.HVAC_MODE_HEAT)
set_config = device.set_configuration
set_config.assert_called_with(heat_mode=HeatMode.HEAT_ON)
def test_dyson_heat_value_on(self): device.environmental_state = None
"""Test get heat value on.""" await hass.async_add_executor_job(update_callback, MockDysonState())
device = _get_device_heat_on() await hass.async_block_till_done()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.hvac_mode == dyson.HVAC_MODE_HEAT
def test_dyson_heat_value_off(self): state = hass.states.get("climate.temp_name")
"""Test get heat value off.""" assert state.attributes.get(ATTR_CURRENT_HUMIDITY) is None
device = _get_device_cool()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.hvac_mode == dyson.HVAC_MODE_COOL
def test_dyson_heat_value_idle(self): device.state.heat_mode = HeatMode.HEAT_OFF.value
"""Test get heat value idle.""" device.state.heat_state = HeatState.HEAT_STATE_OFF.value
device = _get_device_heat_off() await hass.async_add_executor_job(update_callback, MockDysonState())
entity = dyson.DysonPureHotCoolLinkEntity(device) await hass.async_block_till_done()
assert entity.hvac_mode == dyson.HVAC_MODE_HEAT
assert entity.hvac_action == dyson.CURRENT_HVAC_IDLE
def test_on_message(self): state = hass.states.get("climate.temp_name")
"""Test when message is received.""" assert state.state == HVAC_MODE_COOL
device = _get_device_heat_on() assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_COOL
entity = dyson.DysonPureHotCoolLinkEntity(device)
entity.schedule_update_ha_state = Mock()
entity.on_message(MockDysonState())
entity.schedule_update_ha_state.assert_called_with()
def test_general_properties(self):
"""Test properties of entity."""
device = _get_device_with_no_state()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.should_poll is False
assert entity.supported_features == dyson.SUPPORT_FLAGS
assert entity.temperature_unit == TEMP_CELSIUS
def test_property_current_humidity(self): @patch(
"""Test properties of current humidity.""" "homeassistant.components.dyson.DysonAccount.devices",
device = _get_device_heat_on() return_value=[],
entity = dyson.DysonPureHotCoolLinkEntity(device) )
assert entity.current_humidity == 53 @patch("homeassistant.components.dyson.DysonAccount.login", return_value=True)
async def test_setup_component_without_devices(mocked_login, mocked_devices, hass):
"""Test setup component with no devices."""
await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
def test_property_current_humidity_with_invalid_env_state(self): entity_ids = hass.states.async_entity_ids(DOMAIN)
"""Test properties of current humidity with invalid env state.""" assert not entity_ids
device = _get_device_off()
device.environmental_state.humidity = 0
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.current_humidity is None
def test_property_current_humidity_without_env_state(self):
"""Test properties of current humidity without env state."""
device = _get_device_with_no_state()
entity = dyson.DysonPureHotCoolLinkEntity(device)
assert entity.current_humidity is None
def test_property_current_temperature(self): @patch(
"""Test properties of current temperature.""" "homeassistant.components.dyson.DysonAccount.devices",
device = _get_device_heat_on() return_value=[_get_device_heat_on()],
entity = dyson.DysonPureHotCoolLinkEntity(device) )
# Result should be in celsius, hence then subtraction of 273. @patch("homeassistant.components.dyson.DysonAccount.login", return_value=True)
assert entity.current_temperature == 289 - 273 async def test_dyson_set_temperature(mocked_login, mocked_devices, hass):
"""Test set climate temperature."""
await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
def test_property_target_temperature(self): device = mocked_devices.return_value[0]
"""Test properties of target temperature.""" device.temp_unit = TEMP_CELSIUS
device = _get_device_heat_on()
entity = dyson.DysonPureHotCoolLinkEntity(device) # Without correct target temp.
assert entity.target_temperature == 23 await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{
ATTR_ENTITY_ID: "climate.temp_name",
ATTR_TARGET_TEMP_HIGH: 25.0,
ATTR_TARGET_TEMP_LOW: 15.0,
},
True,
)
set_config = device.set_configuration
assert set_config.call_count == 0
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: 23},
True,
)
set_config = device.set_configuration
assert set_config.call_args == call(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23)
)
# Should clip the target temperature between 1 and 37 inclusive.
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: 50},
True,
)
set_config = device.set_configuration
assert set_config.call_args == call(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(37)
)
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: -5},
True,
)
set_config = device.set_configuration
assert set_config.call_args == call(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(1)
)
@patch(
"homeassistant.components.dyson.DysonAccount.devices",
return_value=[_get_device_cool()],
)
@patch("homeassistant.components.dyson.DysonAccount.login", return_value=True)
async def test_dyson_set_temperature_when_cooling_mode(
mocked_login, mocked_devices, hass
):
"""Test set climate temperature when heating is off."""
await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
device = mocked_devices.return_value[0]
device.temp_unit = TEMP_CELSIUS
await hass.services.async_call(
DOMAIN,
SERVICE_SET_TEMPERATURE,
{ATTR_ENTITY_ID: "climate.temp_name", ATTR_TEMPERATURE: 23},
True,
)
set_config = device.set_configuration
assert set_config.call_args == call(
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23)
)
@patch( @patch(
@ -395,10 +400,10 @@ async def test_setup_component_with_parent_discovery(
mocked_login, mocked_devices, hass mocked_login, mocked_devices, hass
): ):
"""Test setup_component using discovery.""" """Test setup_component using discovery."""
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
entity_ids = hass.states.async_entity_ids("climate") entity_ids = hass.states.async_entity_ids(DOMAIN)
assert len(entity_ids) == 2 assert len(entity_ids) == 2
@ -410,10 +415,10 @@ async def test_setup_component_with_parent_discovery(
async def test_purehotcool_component_setup_only_once(devices, login, hass): async def test_purehotcool_component_setup_only_once(devices, login, hass):
"""Test if entities are created only once.""" """Test if entities are created only once."""
config = _get_config() config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config) await async_setup_component(hass, DYSON_DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
entity_ids = hass.states.async_entity_ids("climate") entity_ids = hass.states.async_entity_ids(DOMAIN)
assert len(entity_ids) == 1 assert len(entity_ids) == 1
state = hass.states.get(entity_ids[0]) state = hass.states.get(entity_ids[0])
assert state.name == "Living room" assert state.name == "Living room"
@ -427,10 +432,10 @@ async def test_purehotcool_component_setup_only_once(devices, login, hass):
async def test_purehotcoollink_component_setup_only_once(devices, login, hass): async def test_purehotcoollink_component_setup_only_once(devices, login, hass):
"""Test if entities are created only once.""" """Test if entities are created only once."""
config = _get_config() config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config) await async_setup_component(hass, DYSON_DOMAIN, config)
await hass.async_block_till_done() await hass.async_block_till_done()
entity_ids = hass.states.async_entity_ids("climate") entity_ids = hass.states.async_entity_ids(DOMAIN)
assert len(entity_ids) == 1 assert len(entity_ids) == 1
state = hass.states.get(entity_ids[0]) state = hass.states.get(entity_ids[0])
assert state.name == "Temp Name" assert state.name == "Temp Name"
@ -444,7 +449,7 @@ async def test_purehotcoollink_component_setup_only_once(devices, login, hass):
async def test_purehotcool_update_state(devices, login, hass): async def test_purehotcool_update_state(devices, login, hass):
"""Test state update.""" """Test state update."""
device = devices.return_value[0] device = devices.return_value[0]
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
event = { event = {
"msg": "CURRENT-STATE", "msg": "CURRENT-STATE",
@ -476,12 +481,9 @@ async def test_purehotcool_update_state(devices, login, hass):
}, },
} }
device.state = DysonPureHotCoolV2State(json.dumps(event)) device.state = DysonPureHotCoolV2State(json.dumps(event))
update_callback = device.add_message_listener.call_args[0][0]
for call in device.add_message_listener.call_args_list: await hass.async_add_executor_job(update_callback, device.state)
callback = call[0][0]
if type(callback.__self__) == dyson.DysonPureHotCoolEntity:
callback(device.state)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("climate.living_room") state = hass.states.get("climate.living_room")
attributes = state.attributes attributes = state.attributes
@ -500,7 +502,7 @@ async def test_purehotcool_empty_env_attributes(devices, login, hass):
device = devices.return_value[0] device = devices.return_value[0]
device.environmental_state.temperature = 0 device.environmental_state.temperature = 0
device.environmental_state.humidity = None device.environmental_state.humidity = None
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("climate.living_room") state = hass.states.get("climate.living_room")
@ -518,7 +520,7 @@ async def test_purehotcool_fan_state_off(devices, login, hass):
"""Test device fan state off.""" """Test device fan state off."""
device = devices.return_value[0] device = devices.return_value[0]
device.state.fan_state = FanState.FAN_OFF.value device.state.fan_state = FanState.FAN_OFF.value
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("climate.living_room") state = hass.states.get("climate.living_room")
@ -536,7 +538,7 @@ async def test_purehotcool_hvac_action_cool(devices, login, hass):
"""Test device HVAC action cool.""" """Test device HVAC action cool."""
device = devices.return_value[0] device = devices.return_value[0]
device.state.fan_power = FanPower.POWER_ON.value device.state.fan_power = FanPower.POWER_ON.value
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("climate.living_room") state = hass.states.get("climate.living_room")
@ -555,7 +557,7 @@ async def test_purehotcool_hvac_action_idle(devices, login, hass):
device = devices.return_value[0] device = devices.return_value[0]
device.state.fan_power = FanPower.POWER_ON.value device.state.fan_power = FanPower.POWER_ON.value
device.state.heat_mode = HeatMode.HEAT_ON.value device.state.heat_mode = HeatMode.HEAT_ON.value
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("climate.living_room") state = hass.states.get("climate.living_room")
@ -572,12 +574,12 @@ async def test_purehotcool_hvac_action_idle(devices, login, hass):
async def test_purehotcool_set_temperature(devices, login, hass): async def test_purehotcool_set_temperature(devices, login, hass):
"""Test set temperature.""" """Test set temperature."""
device = devices.return_value[0] device = devices.return_value[0]
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("climate.living_room") state = hass.states.get("climate.living_room")
attributes = state.attributes attributes = state.attributes
min_temp = attributes["min_temp"] min_temp = attributes[ATTR_MIN_TEMP]
max_temp = attributes["max_temp"] max_temp = attributes[ATTR_MAX_TEMP]
await hass.services.async_call( await hass.services.async_call(
DOMAIN, DOMAIN,
@ -623,7 +625,7 @@ async def test_purehotcool_set_temperature(devices, login, hass):
async def test_purehotcool_set_fan_mode(devices, login, hass): async def test_purehotcool_set_fan_mode(devices, login, hass):
"""Test set fan mode.""" """Test set fan mode."""
device = devices.return_value[0] device = devices.return_value[0]
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(
@ -687,7 +689,7 @@ async def test_purehotcool_set_fan_mode(devices, login, hass):
async def test_purehotcool_set_hvac_mode(devices, login, hass): async def test_purehotcool_set_hvac_mode(devices, login, hass):
"""Test set HVAC mode.""" """Test set HVAC mode."""
device = devices.return_value[0] device = devices.return_value[0]
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config()) await async_setup_component(hass, DYSON_DOMAIN, _get_config())
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.services.async_call( await hass.services.async_call(