diff --git a/homeassistant/components/dyson.py b/homeassistant/components/dyson.py index c5aaba6152b397..d1bb1364569365 100644 --- a/homeassistant/components/dyson.py +++ b/homeassistant/components/dyson.py @@ -13,7 +13,7 @@ from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_TIMEOUT, \ CONF_DEVICES -REQUIREMENTS = ['libpurecoollink==0.2.0'] +REQUIREMENTS = ['libpurecoollink==0.4.1'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/fan/dyson.py b/homeassistant/components/fan/dyson.py index de70c35739dfe4..f0ae102f1e6ac7 100644 --- a/homeassistant/components/fan/dyson.py +++ b/homeassistant/components/fan/dyson.py @@ -83,8 +83,8 @@ def async_added_to_hass(self): def on_message(self, message): """Called when new messages received from the fan.""" - from libpurecoollink.dyson import DysonState - if isinstance(message, DysonState): + from libpurecoollink.dyson_pure_state import DysonPureCoolState + if isinstance(message, DysonPureCoolState): _LOGGER.debug("Message received for fan device %s : %s", self.name, message) self.schedule_update_ha_state() diff --git a/homeassistant/components/sensor/dyson.py b/homeassistant/components/sensor/dyson.py index d3839f847ea0e0..f8246d036a873d 100644 --- a/homeassistant/components/sensor/dyson.py +++ b/homeassistant/components/sensor/dyson.py @@ -6,7 +6,7 @@ import logging import asyncio -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import TEMP_CELSIUS, STATE_OFF from homeassistant.components.dyson import DYSON_DEVICES from homeassistant.helpers.entity import Entity @@ -128,6 +128,8 @@ def __init__(self, hass, device): def state(self): """Return Dust value.""" if self._device.environmental_state: + if self._device.environmental_state.humidity == 0: + return STATE_OFF return self._device.environmental_state.humidity return None @@ -151,6 +153,8 @@ def state(self): """Return Dust value.""" if self._device.environmental_state: temperature_kelvin = self._device.environmental_state.temperature + if temperature_kelvin == 0: + return STATE_OFF if self._unit == TEMP_CELSIUS: return float("{0:.1f}".format(temperature_kelvin - 273.15)) return float("{0:.1f}".format(temperature_kelvin * 9 / 5 - 459.67)) @@ -172,7 +176,7 @@ def __init__(self, hass, device): @property def state(self): - """Return Air QUality value.""" + """Return Air Quality value.""" if self._device.environmental_state: return self._device.environmental_state.volatil_organic_compounds return None diff --git a/requirements_all.txt b/requirements_all.txt index d253a77e86d491..ec5829c1e665e6 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -354,7 +354,7 @@ knxip==0.5 libnacl==1.5.2 # homeassistant.components.dyson -libpurecoollink==0.2.0 +libpurecoollink==0.4.1 # homeassistant.components.device_tracker.mikrotik librouteros==1.0.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 1bcd6a6eae2440..269b91b44d536a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -62,7 +62,7 @@ holidays==0.8.1 influxdb==3.0.0 # homeassistant.components.dyson -libpurecoollink==0.2.0 +libpurecoollink==0.4.1 # homeassistant.components.media_player.soundtouch libsoundtouch==0.7.2 diff --git a/tests/components/fan/test_dyson.py b/tests/components/fan/test_dyson.py index e388f31e664a9d..3573b9c9f48f0a 100644 --- a/tests/components/fan/test_dyson.py +++ b/tests/components/fan/test_dyson.py @@ -6,10 +6,10 @@ from homeassistant.components.fan import dyson from tests.common import get_test_home_assistant from libpurecoollink.const import FanSpeed, FanMode, NightMode, Oscillation -from libpurecoollink.dyson import DysonState +from libpurecoollink.dyson_pure_state import DysonPureCoolState -class MockDysonState(DysonState): +class MockDysonState(DysonPureCoolState): """Mock Dyson state.""" def __init__(self): diff --git a/tests/components/sensor/test_dyson.py b/tests/components/sensor/test_dyson.py index 8599346f769510..a4a69b700b3e6f 100644 --- a/tests/components/sensor/test_dyson.py +++ b/tests/components/sensor/test_dyson.py @@ -2,7 +2,8 @@ import unittest from unittest import mock -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, \ + STATE_OFF from homeassistant.components.sensor import dyson from tests.common import get_test_home_assistant @@ -31,6 +32,21 @@ def _get_with_state(): return device +def _get_with_standby_monitoring(): + """Return a valid device with state but with standby monitoring disable.""" + device = mock.Mock() + device.name = "Device_name" + device.state = mock.Mock() + device.state.filter_life = 100 + device.environmental_state = mock.Mock() + device.environmental_state.dust = 5 + device.environmental_state.humidity = 0 + device.environmental_state.temperature = 0 + device.environmental_state.volatil_organic_compounds = 2 + + return device + + class DysonTest(unittest.TestCase): """Dyson Sensor component test class.""" @@ -128,6 +144,17 @@ def test_dyson_humidity_sensor_with_values(self): self.assertEqual(sensor.name, "Device_name humidity") self.assertEqual(sensor.entity_id, "sensor.dyson_1") + def test_dyson_humidity_standby_monitoring(self): + """Test humidity sensor while device is in standby monitoring.""" + sensor = dyson.DysonHumiditySensor(self.hass, + _get_with_standby_monitoring()) + sensor.entity_id = "sensor.dyson_1" + self.assertFalse(sensor.should_poll) + self.assertEqual(sensor.state, STATE_OFF) + self.assertEqual(sensor.unit_of_measurement, '%') + self.assertEqual(sensor.name, "Device_name humidity") + self.assertEqual(sensor.entity_id, "sensor.dyson_1") + def test_dyson_temperature_sensor(self): """Test temperature sensor with no value.""" sensor = dyson.DysonTemperatureSensor(self.hass, @@ -162,6 +189,18 @@ def test_dyson_temperature_sensor_with_values(self): self.assertEqual(sensor.name, "Device_name temperature") self.assertEqual(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(self.hass, + _get_with_standby_monitoring(), + TEMP_CELSIUS) + sensor.entity_id = "sensor.dyson_1" + self.assertFalse(sensor.should_poll) + self.assertEqual(sensor.state, STATE_OFF) + self.assertEqual(sensor.unit_of_measurement, '°C') + self.assertEqual(sensor.name, "Device_name temperature") + self.assertEqual(sensor.entity_id, "sensor.dyson_1") + def test_dyson_air_quality_sensor(self): """Test air quality sensor with no value.""" sensor = dyson.DysonAirQualitySensor(self.hass,