mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Expose internal states and fixed on/off state of Dyson Fans (#15716)
* exposing internal state and fixed onoff state * fixed styling * revert file mode changes * removed self type hints * better unit test and changed the way to return attributes * made wolfie happy
This commit is contained in:
parent
0b6f2f5b91
commit
623f6c841b
@ -18,6 +18,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
CONF_NIGHT_MODE = 'night_mode'
|
CONF_NIGHT_MODE = 'night_mode'
|
||||||
|
|
||||||
|
ATTR_IS_NIGHT_MODE = 'is_night_mode'
|
||||||
|
ATTR_IS_AUTO_MODE = 'is_auto_mode'
|
||||||
|
|
||||||
DEPENDENCIES = ['dyson']
|
DEPENDENCIES = ['dyson']
|
||||||
DYSON_FAN_DEVICES = 'dyson_fan_devices'
|
DYSON_FAN_DEVICES = 'dyson_fan_devices'
|
||||||
|
|
||||||
@ -158,7 +161,7 @@ class DysonPureCoolLinkDevice(FanEntity):
|
|||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if the entity is on."""
|
"""Return true if the entity is on."""
|
||||||
if self._device.state:
|
if self._device.state:
|
||||||
return self._device.state.fan_state == "FAN"
|
return self._device.state.fan_mode == "FAN"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -232,3 +235,11 @@ class DysonPureCoolLinkDevice(FanEntity):
|
|||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return SUPPORT_OSCILLATE | SUPPORT_SET_SPEED
|
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
|
||||||
|
}
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
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.dyson import DYSON_DEVICES
|
||||||
from homeassistant.components.fan import dyson
|
from homeassistant.components.fan import (dyson, ATTR_SPEED, ATTR_SPEED_LIST,
|
||||||
|
ATTR_OSCILLATING)
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant
|
||||||
from libpurecoollink.const import FanSpeed, FanMode, NightMode, Oscillation
|
from libpurecoollink.const import FanSpeed, FanMode, NightMode, Oscillation
|
||||||
from libpurecoollink.dyson_pure_state import DysonPureCoolState
|
from libpurecoollink.dyson_pure_state import DysonPureCoolState
|
||||||
@ -91,6 +94,45 @@ class DysonTest(unittest.TestCase):
|
|||||||
self.hass.data[dyson.DYSON_DEVICES] = [device_fan, device_non_fan]
|
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.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):
|
||||||
|
"""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):
|
def test_dyson_set_speed(self):
|
||||||
"""Test set fan speed."""
|
"""Test set fan speed."""
|
||||||
device = _get_device_on()
|
device = _get_device_on()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user