Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -8,8 +8,7 @@ from libpurecool.dyson_pure_cool_link import DysonPureCoolLink
|
||||
|
||||
from homeassistant.components import dyson as dyson_parent
|
||||
from homeassistant.components.dyson import sensor as dyson
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, \
|
||||
STATE_OFF
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_OFF
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.setup import async_setup_component
|
||||
from tests.common import get_test_home_assistant
|
||||
@@ -31,17 +30,16 @@ def _get_dyson_purecool_device():
|
||||
|
||||
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"
|
||||
}
|
||||
]
|
||||
}}
|
||||
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"}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _get_device_without_state():
|
||||
@@ -103,6 +101,7 @@ class DysonTest(unittest.TestCase):
|
||||
|
||||
def test_setup_component(self):
|
||||
"""Test setup component with devices."""
|
||||
|
||||
def _add_device(devices):
|
||||
assert len(devices) == 5
|
||||
assert devices[0].name == "Device_name Filter Life"
|
||||
@@ -126,7 +125,7 @@ class DysonTest(unittest.TestCase):
|
||||
assert sensor.unit_of_measurement == "hours"
|
||||
assert sensor.name == "Device_name Filter Life"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
sensor.on_message('message')
|
||||
sensor.on_message("message")
|
||||
|
||||
def test_dyson_filter_life_sensor_with_values(self):
|
||||
"""Test filter sensor with values."""
|
||||
@@ -138,7 +137,7 @@ class DysonTest(unittest.TestCase):
|
||||
assert sensor.unit_of_measurement == "hours"
|
||||
assert sensor.name == "Device_name Filter Life"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
sensor.on_message('message')
|
||||
sensor.on_message("message")
|
||||
|
||||
def test_dyson_dust_sensor(self):
|
||||
"""Test dust sensor with no value."""
|
||||
@@ -169,7 +168,7 @@ class DysonTest(unittest.TestCase):
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state is None
|
||||
assert sensor.unit_of_measurement == '%'
|
||||
assert sensor.unit_of_measurement == "%"
|
||||
assert sensor.name == "Device_name Humidity"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
@@ -180,7 +179,7 @@ class DysonTest(unittest.TestCase):
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state == 45
|
||||
assert sensor.unit_of_measurement == '%'
|
||||
assert sensor.unit_of_measurement == "%"
|
||||
assert sensor.name == "Device_name Humidity"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
@@ -191,53 +190,51 @@ class DysonTest(unittest.TestCase):
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state == STATE_OFF
|
||||
assert sensor.unit_of_measurement == '%'
|
||||
assert sensor.unit_of_measurement == "%"
|
||||
assert sensor.name == "Device_name Humidity"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
def test_dyson_temperature_sensor(self):
|
||||
"""Test temperature sensor with no value."""
|
||||
sensor = dyson.DysonTemperatureSensor(_get_device_without_state(),
|
||||
TEMP_CELSIUS)
|
||||
sensor = dyson.DysonTemperatureSensor(_get_device_without_state(), TEMP_CELSIUS)
|
||||
sensor.hass = self.hass
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state is None
|
||||
assert sensor.unit_of_measurement == '°C'
|
||||
assert sensor.unit_of_measurement == "°C"
|
||||
assert sensor.name == "Device_name Temperature"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
def test_dyson_temperature_sensor_with_values(self):
|
||||
"""Test temperature sensor with values."""
|
||||
sensor = dyson.DysonTemperatureSensor(_get_with_state(),
|
||||
TEMP_CELSIUS)
|
||||
sensor = dyson.DysonTemperatureSensor(_get_with_state(), TEMP_CELSIUS)
|
||||
sensor.hass = self.hass
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state == 21.9
|
||||
assert sensor.unit_of_measurement == '°C'
|
||||
assert sensor.unit_of_measurement == "°C"
|
||||
assert sensor.name == "Device_name Temperature"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
sensor = dyson.DysonTemperatureSensor(_get_with_state(),
|
||||
TEMP_FAHRENHEIT)
|
||||
sensor = dyson.DysonTemperatureSensor(_get_with_state(), TEMP_FAHRENHEIT)
|
||||
sensor.hass = self.hass
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state == 71.3
|
||||
assert sensor.unit_of_measurement == '°F'
|
||||
assert sensor.unit_of_measurement == "°F"
|
||||
assert sensor.name == "Device_name Temperature"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
def test_dyson_temperature_standby_monitoring(self):
|
||||
"""Test temperature sensor while device is in standby monitoring."""
|
||||
sensor = dyson.DysonTemperatureSensor(_get_with_standby_monitoring(),
|
||||
TEMP_CELSIUS)
|
||||
sensor = dyson.DysonTemperatureSensor(
|
||||
_get_with_standby_monitoring(), TEMP_CELSIUS
|
||||
)
|
||||
sensor.hass = self.hass
|
||||
sensor.entity_id = "sensor.dyson_1"
|
||||
assert not sensor.should_poll
|
||||
assert sensor.state == STATE_OFF
|
||||
assert sensor.unit_of_measurement == '°C'
|
||||
assert sensor.unit_of_measurement == "°C"
|
||||
assert sensor.name == "Device_name Temperature"
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
@@ -264,9 +261,11 @@ class DysonTest(unittest.TestCase):
|
||||
assert sensor.entity_id == "sensor.dyson_1"
|
||||
|
||||
|
||||
@asynctest.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
|
||||
@asynctest.patch('libpurecool.dyson.DysonAccount.devices',
|
||||
return_value=[_get_dyson_purecool_device()])
|
||||
@asynctest.patch("libpurecool.dyson.DysonAccount.login", return_value=True)
|
||||
@asynctest.patch(
|
||||
"libpurecool.dyson.DysonAccount.devices",
|
||||
return_value=[_get_dyson_purecool_device()],
|
||||
)
|
||||
async def test_purecool_component_setup_only_once(devices, login, hass):
|
||||
"""Test if entities are created only once."""
|
||||
config = _get_config()
|
||||
|
||||
Reference in new issue
Block a user