1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add sensor support for dyson 2018 models (#22578)

fix check for already created entities

remove hepa and carbon filter

add AQI attribute

initial commit

fix check for already created entities

remove hepa and carbon filter

add AQI attribute

add air quality component tests

fix method call tests

fix line lengths

fix pylint issues

fix docstrings

revert fan related changes

remove whitespace change

fix fan update state test

add for loop for platform initialization

add requested changes to aiq platform

change string concatenation to new style string formatting

update air quality tests

update air quality tests

refactor sensor component changes

fix pylint issues

fix debug string in the air quality component

replace failing tests for older devices

fix line length fan tests

remove dependencies const and move imports

move back imports to methods

remove whitespace from blank line
This commit is contained in:
etheralm
2019-04-30 02:24:05 +02:00
committed by Martin Hjelmare
parent b4e2a0ef84
commit 1d70005b01
9 changed files with 430 additions and 112 deletions

View File

@@ -2,17 +2,51 @@
import unittest
from unittest import mock
import asynctest
from libpurecool.dyson_pure_cool import DysonPureCool
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.helpers import discovery
from homeassistant.setup import async_setup_component
from tests.common import get_test_home_assistant
def _get_dyson_purecool_device():
"""Return a valid device provide by Dyson web services."""
device = mock.Mock(spec=DysonPureCool)
device.serial = "XX-XXXXX-XX"
device.name = "Living room"
device.connect = mock.Mock(return_value=True)
device.auto_connect = mock.Mock(return_value=True)
device.environmental_state.humidity = 42
device.environmental_state.temperature = 280
device.state.hepa_filter_state = 90
device.state.carbon_filter_state = 80
return 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"
}
]
}}
def _get_device_without_state():
"""Return a valid device provide by Dyson web services."""
device = mock.Mock()
device = mock.Mock(spec=DysonPureCoolLink)
device.name = "Device_name"
device.state = None
device.environmental_state = None
@@ -21,7 +55,7 @@ def _get_device_without_state():
def _get_with_state():
"""Return a valid device with state values."""
device = mock.Mock(spec=DysonPureCoolLink)
device = mock.Mock()
device.name = "Device_name"
device.state = mock.Mock()
device.state.filter_life = 100
@@ -65,7 +99,7 @@ class DysonTest(unittest.TestCase):
self.hass.data[dyson.DYSON_DEVICES] = []
add_entities = mock.MagicMock()
dyson.setup_platform(self.hass, None, add_entities)
add_entities.assert_called_with([])
add_entities.assert_not_called()
def test_setup_component(self):
"""Test setup component with devices."""
@@ -80,7 +114,7 @@ class DysonTest(unittest.TestCase):
device_fan = _get_device_without_state()
device_non_fan = _get_with_state()
self.hass.data[dyson.DYSON_DEVICES] = [device_fan, device_non_fan]
dyson.setup_platform(self.hass, None, _add_device)
dyson.setup_platform(self.hass, None, _add_device, mock.MagicMock())
def test_dyson_filter_life_sensor(self):
"""Test filter life sensor with no value."""
@@ -228,3 +262,17 @@ class DysonTest(unittest.TestCase):
assert sensor.unit_of_measurement is None
assert sensor.name == "Device_name AQI"
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()])
async def test_purecool_component_setup_only_once(devices, login, hass):
"""Test if entities are created only once."""
config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config)
await hass.async_block_till_done()
discovery.load_platform(hass, "sensor", dyson_parent.DOMAIN, {}, config)
await hass.async_block_till_done()
assert len(hass.data[dyson.DYSON_SENSOR_DEVICES]) == 2