mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Remove service helper (2) (#16863)
* alarm_control_panel * automation * camera * climate * counter * fan * Add legacy notes * Fix tests
This commit is contained in:
82
tests/components/fan/common.py
Normal file
82
tests/components/fan/common.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""Collection of helper methods.
|
||||
|
||||
All containing methods are legacy helpers that should not be used by new
|
||||
components. Instead call the service directly.
|
||||
"""
|
||||
from homeassistant.components.fan import (
|
||||
ATTR_DIRECTION, ATTR_SPEED, ATTR_OSCILLATING, DOMAIN,
|
||||
SERVICE_OSCILLATE, SERVICE_SET_DIRECTION, SERVICE_SET_SPEED)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TOGGLE, SERVICE_TURN_OFF)
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id: str = None, speed: str = None) -> None:
|
||||
"""Turn all or specified fan on."""
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
(ATTR_ENTITY_ID, entity_id),
|
||||
(ATTR_SPEED, speed),
|
||||
] if value is not None
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id: str = None) -> None:
|
||||
"""Turn all or specified fan off."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id: str = None) -> None:
|
||||
"""Toggle all or specified fans."""
|
||||
data = {
|
||||
ATTR_ENTITY_ID: entity_id
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def oscillate(hass, entity_id: str = None,
|
||||
should_oscillate: bool = True) -> None:
|
||||
"""Set oscillation on all or specified fan."""
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
(ATTR_ENTITY_ID, entity_id),
|
||||
(ATTR_OSCILLATING, should_oscillate),
|
||||
] if value is not None
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_OSCILLATE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_speed(hass, entity_id: str = None, speed: str = None) -> None:
|
||||
"""Set speed for all or specified fan."""
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
(ATTR_ENTITY_ID, entity_id),
|
||||
(ATTR_SPEED, speed),
|
||||
] if value is not None
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_SET_SPEED, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_direction(hass, entity_id: str = None, direction: str = None) -> None:
|
||||
"""Set direction for all or specified fan."""
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
(ATTR_ENTITY_ID, entity_id),
|
||||
(ATTR_DIRECTION, direction),
|
||||
] if value is not None
|
||||
}
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_SET_DIRECTION, data)
|
||||
Reference in New Issue
Block a user