Skip to content
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

Merged
merged 6 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion homeassistant/components/fan/dyson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace before ':'

ATTR_IS_AUTO_MODE : self.is_auto_mode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace before ':'

}
45 changes: 44 additions & 1 deletion tests/components/fan/test_dyson.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Test the Dyson fan component."""
import asyncio

Choose a reason for hiding this comment

The 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,

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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):

Choose a reason for hiding this comment

The 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()
Expand Down