mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +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
|
||||
def oscillating(self):
|
||||
"""Return the oscillation state."""
|
||||
return self._device.state and self._device.state.oscillation == "ON"
|
||||
return self._device.state.oscillation == "ON"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the entity is on."""
|
||||
if self._device.state:
|
||||
return self._device.state.fan_mode in ["FAN", "AUTO"]
|
||||
return False
|
||||
|
||||
@property
|
||||
def speed(self) -> str:
|
||||
"""Return the current speed."""
|
||||
if self._device.state:
|
||||
if self._device.state.speed == FanSpeed.FAN_SPEED_AUTO.value:
|
||||
return 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:
|
||||
"""Turn fan in night mode."""
|
||||
@ -414,9 +405,7 @@ class DysonPureCoolEntity(DysonFanEntity):
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the entity is on."""
|
||||
if self._device.state:
|
||||
return self._device.state.fan_power == "ON"
|
||||
return False
|
||||
|
||||
@property
|
||||
def speed(self):
|
||||
@ -503,11 +492,6 @@ class DysonPureCoolEntity(DysonFanEntity):
|
||||
int(FanSpeed.FAN_SPEED_10.value),
|
||||
]
|
||||
|
||||
@property
|
||||
def device_serial(self):
|
||||
"""Return fan's serial number."""
|
||||
return self._device.serial
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
|
@ -18,8 +18,12 @@ BASE_PATH = "homeassistant.components.dyson"
|
||||
@pytest.fixture
|
||||
async def device(hass: HomeAssistant, request) -> DysonDevice:
|
||||
"""Fixture to provide Dyson 360 Eye device."""
|
||||
device = request.module.get_device()
|
||||
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(
|
||||
f"{BASE_PATH}.DysonAccount.devices", return_value=[device]
|
||||
), 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."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from libpurecool.const import Dyson360EyeMode, PowerMode
|
||||
from libpurecool.dyson_360_eye import Dyson360Eye
|
||||
import pytest
|
||||
@ -34,11 +32,10 @@ ENTITY_ID = f"{PLATFORM_DOMAIN}.{ENTITY_NAME}"
|
||||
|
||||
|
||||
@callback
|
||||
def get_device() -> Dyson360Eye:
|
||||
def get_device(state=Dyson360EyeMode.FULL_CLEAN_RUNNING) -> Dyson360Eye:
|
||||
"""Return a Dyson 360 Eye device."""
|
||||
device = get_basic_device(Dyson360Eye)
|
||||
device.state = MagicMock()
|
||||
device.state.state = Dyson360EyeMode.FULL_CLEAN_RUNNING
|
||||
device.state.state = state
|
||||
device.state.battery_level = 85
|
||||
device.state.power_mode = PowerMode.QUIET
|
||||
device.state.position = (0, 0)
|
||||
@ -77,7 +74,7 @@ async def test_state(hass: HomeAssistant, device: Dyson360Eye) -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"service,command,state",
|
||||
"service,command,device",
|
||||
[
|
||||
(SERVICE_TURN_ON, "start", Dyson360EyeMode.INACTIVE_CHARGED),
|
||||
(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_RETURN_TO_BASE, "abort", Dyson360EyeMode.FULL_CLEAN_PAUSED),
|
||||
],
|
||||
indirect=["device"],
|
||||
)
|
||||
async def test_commands(
|
||||
hass: HomeAssistant, device: Dyson360Eye, service: str, command: str, state: str
|
||||
hass: HomeAssistant, device: Dyson360Eye, service: str, command: str
|
||||
) -> None:
|
||||
"""Test sending commands to the vacuum."""
|
||||
device.state.state = state
|
||||
await async_update_device(hass, device)
|
||||
await hass.services.async_call(
|
||||
PLATFORM_DOMAIN, service, {ATTR_ENTITY_ID: ENTITY_ID}, blocking=True
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user