-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose internal states and fixed on/off state of Dyson Fans #15716
Changes from 5 commits
e0bb523
629f609
2007cfd
9710cfe
80d3180
535bcf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ | |
|
||
CONF_NIGHT_MODE = 'night_mode' | ||
|
||
ATTR_IS_NIGHT_MODE = 'is_night_mode' | ||
ATTR_IS_AUTO_MODE = 'is_auto_mode' | ||
|
||
DEPENDENCIES = ['dyson'] | ||
DYSON_FAN_DEVICES = 'dyson_fan_devices' | ||
|
||
|
@@ -159,7 +162,7 @@ def oscillating(self): | |
def is_on(self): | ||
"""Return true if the entity is on.""" | ||
if self._device.state: | ||
return self._device.state.fan_state == "FAN" | ||
return self._device.state.fan_mode == "FAN" | ||
return False | ||
|
||
@property | ||
|
@@ -233,3 +236,11 @@ def speed_list(self: ToggleEntity) -> list: | |
def supported_features(self: ToggleEntity) -> int: | ||
"""Flag supported features.""" | ||
return SUPPORT_OSCILLATE | SUPPORT_SET_SPEED | ||
|
||
@property | ||
def device_state_attributes(self) -> dict: | ||
"""Return optional state attributes.""" | ||
return { | ||
ATTR_IS_NIGHT_MODE : self.is_night_mode, | ||
ATTR_IS_AUTO_MODE : self.is_auto_mode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whitespace before ':' |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
"""Test the Dyson fan component.""" | ||
import asyncio | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'asyncio' imported but unused |
||
import unittest | ||
from unittest import mock | ||
|
||
from homeassistant.setup import setup_component | ||
from homeassistant.components import dyson as dyson_parent | ||
from homeassistant.components.dyson import DYSON_DEVICES | ||
from homeassistant.components.fan import dyson | ||
from homeassistant.components.fan import (dyson, ATTR_SPEED, ATTR_SPEED_LIST, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'homeassistant.components.fan.ATTR_DIRECTION' imported but unused |
||
ATTR_OSCILLATING) | ||
from tests.common import get_test_home_assistant | ||
from libpurecoollink.const import FanSpeed, FanMode, NightMode, Oscillation | ||
from libpurecoollink.dyson_pure_state import DysonPureCoolState | ||
|
@@ -91,6 +95,45 @@ def _add_device(devices): | |
self.hass.data[dyson.DYSON_DEVICES] = [device_fan, device_non_fan] | ||
dyson.setup_platform(self.hass, None, _add_device) | ||
|
||
@mock.patch('libpurecoollink.dyson.DysonAccount.devices', | ||
return_value=[_get_device_on()]) | ||
@mock.patch('libpurecoollink.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( | ||
dyson.DOMAIN, | ||
mocked_devices.return_value[0].name)) | ||
|
||
assert dyson.ATTR_IS_NIGHT_MODE in state.attributes | ||
assert dyson.ATTR_IS_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('libpurecoollink.dyson.DysonAccount.devices', | ||
return_value=[_get_device_on()]) | ||
@mock.patch('libpurecoollink.dyson.DysonAccount.login', return_value=True) | ||
def test_async_added_to_hass(self,mocked_login, mocked_devices): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing whitespace after ',' |
||
"""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() | ||
self.assertEqual(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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespace before ':'