mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Rewrite dyson fan test (#45295)
* Improve device fixture to take parameter * Remove unused code in dyson/fan * Rewrite dyson fan test
This commit is contained in:
parent
07c3981de7
commit
c929fbeea3
@ -237,28 +237,19 @@ class DysonPureCoolLinkEntity(DysonFanEntity):
|
|||||||
@property
|
@property
|
||||||
def oscillating(self):
|
def oscillating(self):
|
||||||
"""Return the oscillation state."""
|
"""Return the oscillation state."""
|
||||||
return self._device.state and self._device.state.oscillation == "ON"
|
return self._device.state.oscillation == "ON"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
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:
|
return self._device.state.fan_mode in ["FAN", "AUTO"]
|
||||||
return self._device.state.fan_mode in ["FAN", "AUTO"]
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def speed(self) -> str:
|
def speed(self) -> str:
|
||||||
"""Return the current speed."""
|
"""Return the current speed."""
|
||||||
if self._device.state:
|
if self._device.state.speed == FanSpeed.FAN_SPEED_AUTO.value:
|
||||||
if self._device.state.speed == FanSpeed.FAN_SPEED_AUTO.value:
|
return self._device.state.speed
|
||||||
return self._device.state.speed
|
return int(self._device.state.speed)
|
||||||
return int(self._device.state.speed)
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def current_direction(self):
|
|
||||||
"""Return direction of the fan [forward, reverse]."""
|
|
||||||
return None
|
|
||||||
|
|
||||||
def set_night_mode(self, night_mode: bool) -> None:
|
def set_night_mode(self, night_mode: bool) -> None:
|
||||||
"""Turn fan in night mode."""
|
"""Turn fan in night mode."""
|
||||||
@ -414,9 +405,7 @@ class DysonPureCoolEntity(DysonFanEntity):
|
|||||||
@property
|
@property
|
||||||
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:
|
return self._device.state.fan_power == "ON"
|
||||||
return self._device.state.fan_power == "ON"
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def speed(self):
|
def speed(self):
|
||||||
@ -503,11 +492,6 @@ class DysonPureCoolEntity(DysonFanEntity):
|
|||||||
int(FanSpeed.FAN_SPEED_10.value),
|
int(FanSpeed.FAN_SPEED_10.value),
|
||||||
]
|
]
|
||||||
|
|
||||||
@property
|
|
||||||
def device_serial(self):
|
|
||||||
"""Return fan's serial number."""
|
|
||||||
return self._device.serial
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
|
@ -18,8 +18,12 @@ BASE_PATH = "homeassistant.components.dyson"
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def device(hass: HomeAssistant, request) -> DysonDevice:
|
async def device(hass: HomeAssistant, request) -> DysonDevice:
|
||||||
"""Fixture to provide Dyson 360 Eye device."""
|
"""Fixture to provide Dyson 360 Eye device."""
|
||||||
device = request.module.get_device()
|
|
||||||
platform = request.module.PLATFORM_DOMAIN
|
platform = request.module.PLATFORM_DOMAIN
|
||||||
|
get_device = request.module.get_device
|
||||||
|
if hasattr(request, "param"):
|
||||||
|
device = get_device(request.param)
|
||||||
|
else:
|
||||||
|
device = get_device()
|
||||||
with patch(f"{BASE_PATH}.DysonAccount.login", return_value=True), patch(
|
with patch(f"{BASE_PATH}.DysonAccount.login", return_value=True), patch(
|
||||||
f"{BASE_PATH}.DysonAccount.devices", return_value=[device]
|
f"{BASE_PATH}.DysonAccount.devices", return_value=[device]
|
||||||
), patch(f"{BASE_PATH}.DYSON_PLATFORMS", [platform]):
|
), patch(f"{BASE_PATH}.DYSON_PLATFORMS", [platform]):
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,4 @@
|
|||||||
"""Test the Dyson 360 eye robot vacuum component."""
|
"""Test the Dyson 360 eye robot vacuum component."""
|
||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
from libpurecool.const import Dyson360EyeMode, PowerMode
|
from libpurecool.const import Dyson360EyeMode, PowerMode
|
||||||
from libpurecool.dyson_360_eye import Dyson360Eye
|
from libpurecool.dyson_360_eye import Dyson360Eye
|
||||||
import pytest
|
import pytest
|
||||||
@ -34,11 +32,10 @@ ENTITY_ID = f"{PLATFORM_DOMAIN}.{ENTITY_NAME}"
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def get_device() -> Dyson360Eye:
|
def get_device(state=Dyson360EyeMode.FULL_CLEAN_RUNNING) -> Dyson360Eye:
|
||||||
"""Return a Dyson 360 Eye device."""
|
"""Return a Dyson 360 Eye device."""
|
||||||
device = get_basic_device(Dyson360Eye)
|
device = get_basic_device(Dyson360Eye)
|
||||||
device.state = MagicMock()
|
device.state.state = state
|
||||||
device.state.state = Dyson360EyeMode.FULL_CLEAN_RUNNING
|
|
||||||
device.state.battery_level = 85
|
device.state.battery_level = 85
|
||||||
device.state.power_mode = PowerMode.QUIET
|
device.state.power_mode = PowerMode.QUIET
|
||||||
device.state.position = (0, 0)
|
device.state.position = (0, 0)
|
||||||
@ -77,7 +74,7 @@ async def test_state(hass: HomeAssistant, device: Dyson360Eye) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"service,command,state",
|
"service,command,device",
|
||||||
[
|
[
|
||||||
(SERVICE_TURN_ON, "start", Dyson360EyeMode.INACTIVE_CHARGED),
|
(SERVICE_TURN_ON, "start", Dyson360EyeMode.INACTIVE_CHARGED),
|
||||||
(SERVICE_TURN_ON, "resume", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
(SERVICE_TURN_ON, "resume", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
||||||
@ -89,13 +86,12 @@ async def test_state(hass: HomeAssistant, device: Dyson360Eye) -> None:
|
|||||||
(SERVICE_START_PAUSE, "resume", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
(SERVICE_START_PAUSE, "resume", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
||||||
(SERVICE_RETURN_TO_BASE, "abort", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
(SERVICE_RETURN_TO_BASE, "abort", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
||||||
],
|
],
|
||||||
|
indirect=["device"],
|
||||||
)
|
)
|
||||||
async def test_commands(
|
async def test_commands(
|
||||||
hass: HomeAssistant, device: Dyson360Eye, service: str, command: str, state: str
|
hass: HomeAssistant, device: Dyson360Eye, service: str, command: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sending commands to the vacuum."""
|
"""Test sending commands to the vacuum."""
|
||||||
device.state.state = state
|
|
||||||
await async_update_device(hass, device)
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
PLATFORM_DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_ID}, blocking=True
|
PLATFORM_DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_ID}, blocking=True
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user