This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+30 -35
View File
@@ -3,8 +3,7 @@ import unittest
from unittest import mock
import asynctest
from libpurecool.const import (FocusMode, HeatMode,
HeatState, HeatTarget, TiltState)
from libpurecool.const import FocusMode, HeatMode, HeatState, HeatTarget, TiltState
from libpurecool.dyson_pure_hotcool_link import DysonPureHotCoolLink
from libpurecool.dyson_pure_state import DysonPureHotCoolState
@@ -25,21 +24,17 @@ class MockDysonState(DysonPureHotCoolState):
def _get_config():
"""Return a config dictionary."""
return {dyson_parent.DOMAIN: {
dyson_parent.CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "GB",
dyson_parent.CONF_DEVICES: [
{
"device_id": "XX-XXXXX-XX",
"device_ip": "192.168.0.1"
},
{
"device_id": "YY-YYYYY-YY",
"device_ip": "192.168.0.2"
}
]
}}
return {
dyson_parent.DOMAIN: {
dyson_parent.CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "GB",
dyson_parent.CONF_DEVICES: [
{"device_id": "XX-XXXXX-XX", "device_ip": "192.168.0.1"},
{"device_id": "YY-YYYYY-YY", "device_ip": "192.168.0.2"},
],
}
}
def _get_device_with_no_state():
@@ -145,7 +140,7 @@ class DysonTest(unittest.TestCase):
devices = [
_get_device_with_no_state(),
_get_device_off(),
_get_device_heat_on()
_get_device_heat_on(),
]
self.hass.data[dyson.DYSON_DEVICES] = devices
add_devices = mock.MagicMock()
@@ -154,10 +149,7 @@ class DysonTest(unittest.TestCase):
def test_setup_component_with_invalid_devices(self):
"""Test setup component with invalid devices."""
devices = [
None,
"foo_bar"
]
devices = [None, "foo_bar"]
self.hass.data[dyson.DYSON_DEVICES] = devices
add_devices = mock.MagicMock()
dyson.setup_platform(self.hass, None, add_devices, discovery_info={})
@@ -192,23 +184,23 @@ class DysonTest(unittest.TestCase):
entity.set_temperature(**kwargs)
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON,
heat_target=HeatTarget.celsius(23))
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23)
)
# Should clip the target temperature between 1 and 37 inclusive.
kwargs = {ATTR_TEMPERATURE: 50}
entity.set_temperature(**kwargs)
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON,
heat_target=HeatTarget.celsius(37))
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(37)
)
kwargs = {ATTR_TEMPERATURE: -5}
entity.set_temperature(**kwargs)
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON,
heat_target=HeatTarget.celsius(1))
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(1)
)
def test_dyson_set_temperature_when_cooling_mode(self):
"""Test set climate temperature when heating is off."""
@@ -221,8 +213,8 @@ class DysonTest(unittest.TestCase):
entity.set_temperature(**kwargs)
set_config = device.set_configuration
set_config.assert_called_with(
heat_mode=HeatMode.HEAT_ON,
heat_target=HeatTarget.celsius(23))
heat_mode=HeatMode.HEAT_ON, heat_target=HeatTarget.celsius(23)
)
def test_dyson_set_fan_mode(self):
"""Test set fan mode."""
@@ -364,11 +356,14 @@ class DysonTest(unittest.TestCase):
assert entity.target_temperature == 23
@asynctest.patch('libpurecool.dyson.DysonAccount.devices',
return_value=[_get_device_heat_on(), _get_device_cool()])
@asynctest.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
async def test_setup_component_with_parent_discovery(mocked_login,
mocked_devices, hass):
@asynctest.patch(
"libpurecool.dyson.DysonAccount.devices",
return_value=[_get_device_heat_on(), _get_device_cool()],
)
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
async def test_setup_component_with_parent_discovery(
mocked_login, mocked_devices, hass
):
"""Test setup_component using discovery."""
await async_setup_component(hass, dyson_parent.DOMAIN, _get_config())
await hass.async_block_till_done()