1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +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

@@ -13,7 +13,7 @@ from libpurecool.dyson_pure_state_v2 import DysonPureCoolV2State
import homeassistant.components.dyson.fan as dyson
from homeassistant.components import dyson as dyson_parent
from homeassistant.components.dyson import DYSON_DEVICES
from homeassistant.components.fan import (DOMAIN, ATTR_SPEED, ATTR_SPEED_LIST,
from homeassistant.components.fan import (DOMAIN, ATTR_SPEED,
ATTR_OSCILLATING, SPEED_LOW,
SPEED_MEDIUM, SPEED_HIGH,
SERVICE_OSCILLATE)
@@ -21,7 +21,7 @@ from homeassistant.const import (SERVICE_TURN_ON,
SERVICE_TURN_OFF,
ATTR_ENTITY_ID)
from homeassistant.helpers import discovery
from homeassistant.setup import setup_component, async_setup_component
from homeassistant.setup import async_setup_component
from tests.common import get_test_home_assistant
@@ -55,6 +55,21 @@ def _get_dyson_purecool_device():
return device
def _get_dyson_purecoollink_device():
"""Return a valid device as provided by the Dyson web services."""
device = mock.Mock(spec=DysonPureCoolLink)
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.state = mock.Mock()
device.state.oscillation = "ON"
device.state.fan_mode = "FAN"
device.state.speed = FanSpeed.FAN_SPEED_AUTO.value
device.state.night_mode = "OFF"
return device
def _get_supported_speeds():
return [
int(FanSpeed.FAN_SPEED_1.value),
@@ -173,45 +188,6 @@ class DysonTest(unittest.TestCase):
"""Stop everything that was started."""
self.hass.stop()
@mock.patch('libpurecool.dyson.DysonAccount.devices',
return_value=[_get_device_on()])
@mock.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
def test_get_state_attributes(self, mocked_login, mocked_devices):
"""Test async added to hass."""
setup_component(self.hass, dyson_parent.DOMAIN, {
dyson_parent.DOMAIN: {
dyson_parent.CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "US",
}
})
self.hass.block_till_done()
state = self.hass.states.get("{}.{}".format(
DOMAIN,
mocked_devices.return_value[0].name))
assert dyson.ATTR_NIGHT_MODE in state.attributes
assert dyson.ATTR_AUTO_MODE in state.attributes
assert ATTR_SPEED in state.attributes
assert ATTR_SPEED_LIST in state.attributes
assert ATTR_OSCILLATING in state.attributes
@mock.patch('libpurecool.dyson.DysonAccount.devices',
return_value=[_get_device_on()])
@mock.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
def test_async_added_to_hass(self, mocked_login, mocked_devices):
"""Test async added to hass."""
setup_component(self.hass, dyson_parent.DOMAIN, {
dyson_parent.DOMAIN: {
dyson_parent.CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "US",
}
})
self.hass.block_till_done()
assert len(self.hass.data[dyson.DYSON_DEVICES]) == 1
assert mocked_devices.return_value[0].add_message_listener.called
def test_dyson_set_speed(self):
"""Test set fan speed."""
device = _get_device_on()
@@ -415,6 +391,22 @@ class DysonTest(unittest.TestCase):
dyson_device.set_night_mode.assert_called_with(True)
@asynctest.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
@asynctest.patch('libpurecool.dyson.DysonAccount.devices',
return_value=[_get_dyson_purecoollink_device()])
async def test_purecoollink_attributes(devices, login, hass):
"""Test state attributes."""
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
fan_state = hass.states.get("fan.living_room")
attributes = fan_state.attributes
assert fan_state.state == "on"
assert attributes[dyson.ATTR_NIGHT_MODE] is False
assert attributes[ATTR_SPEED] == FanSpeed.FAN_SPEED_AUTO.value
assert attributes[ATTR_OSCILLATING] is True
@asynctest.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
@asynctest.patch('libpurecool.dyson.DysonAccount.devices',
return_value=[_get_dyson_purecool_device()])
@@ -670,31 +662,6 @@ async def test_purecool_set_timer(devices, login, hass):
assert device.disable_sleep_timer.call_count == 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_attributes(devices, login, hass):
"""Test state attributes."""
await async_setup_component(hass, dyson.DYSON_DOMAIN, _get_config())
await hass.async_block_till_done()
fan_state = hass.states.get("fan.living_room")
attributes = fan_state.attributes
assert fan_state.state == "on"
assert attributes[dyson.ATTR_NIGHT_MODE] is False
assert attributes[dyson.ATTR_AUTO_MODE] is True
assert attributes[dyson.ATTR_ANGLE_LOW] == 90
assert attributes[dyson.ATTR_ANGLE_HIGH] == 180
assert attributes[dyson.ATTR_FLOW_DIRECTION_FRONT] is True
assert attributes[dyson.ATTR_TIMER] == 60
assert attributes[dyson.ATTR_HEPA_FILTER] == 90
assert attributes[dyson.ATTR_CARBON_FILTER] == 80
assert attributes[dyson.ATTR_DYSON_SPEED] == FanSpeed.FAN_SPEED_AUTO.value
assert attributes[ATTR_SPEED] == SPEED_MEDIUM
assert attributes[ATTR_OSCILLATING] is True
assert attributes[dyson.ATTR_DYSON_SPEED_LIST] == _get_supported_speeds()
@asynctest.patch('libpurecool.dyson.DysonAccount.login', return_value=True)
@asynctest.patch('libpurecool.dyson.DysonAccount.devices',
return_value=[_get_dyson_purecool_device()])
@@ -713,7 +680,7 @@ async def test_purecool_update_state(devices, login, hass):
"osau": "0095", "ancp": "CUST"}}
device.state = DysonPureCoolV2State(json.dumps(event))
callback = device.add_message_listener.call_args_list[0][0][0]
callback = device.add_message_listener.call_args_list[3][0][0]
callback(device.state)
await hass.async_block_till_done()
fan_state = hass.states.get("fan.living_room")