Fix Dyson sensors if devices are configured without standby monitoring. Fixes #8569 (#8826)

Upgrade libpurecoolink libraries without unused enum34 dependency
pull/8828/head
Charles Blonde 2017-08-04 23:27:23 +02:00 committed by Paulus Schoutsen
parent cf298c2435
commit 7f0d0607f1
7 changed files with 53 additions and 10 deletions

View File

@ -13,7 +13,7 @@ from homeassistant.helpers import discovery
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__)

View File

@ -83,8 +83,8 @@ class DysonPureCoolLinkDevice(FanEntity):
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()

View File

@ -6,7 +6,7 @@ https://home-assistant.io/components/sensor.dyson/
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 @@ class DysonHumiditySensor(DysonSensor):
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 @@ class DysonTemperatureSensor(DysonSensor):
"""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 @@ class DysonAirQualitySensor(DysonSensor):
@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

View File

@ -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

View File

@ -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

View File

@ -6,10 +6,10 @@ from homeassistant.components.dyson import DYSON_DEVICES
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):

View File

@ -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 @@ class DysonTest(unittest.TestCase):
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 @@ class DysonTest(unittest.TestCase):
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,