2018-09-26 07:49:55 +00:00
|
|
|
"""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 (
|
2018-09-26 16:03:13 +00:00
|
|
|
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
2018-09-26 07:49:55 +00:00
|
|
|
from homeassistant.loader import bind_hass
|
2018-11-02 20:08:22 +00:00
|
|
|
from homeassistant.core import callback
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
@callback
|
2018-09-26 07:49:55 +00:00
|
|
|
@bind_hass
|
2018-11-02 20:08:22 +00:00
|
|
|
def async_turn_on(hass, entity_id: str = None, speed: str = None) -> None:
|
2018-09-26 07:49:55 +00:00
|
|
|
"""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
|
|
|
|
}
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
hass.async_create_task(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data))
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
@callback
|
2018-09-26 07:49:55 +00:00
|
|
|
@bind_hass
|
2018-11-02 20:08:22 +00:00
|
|
|
def async_turn_off(hass, entity_id: str = None) -> None:
|
2018-09-26 07:49:55 +00:00
|
|
|
"""Turn all or specified fan off."""
|
|
|
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
hass.async_create_task(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data))
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
@callback
|
2018-09-26 07:49:55 +00:00
|
|
|
@bind_hass
|
2018-11-02 20:08:22 +00:00
|
|
|
def async_oscillate(hass, entity_id: str = None,
|
|
|
|
should_oscillate: bool = True) -> None:
|
2018-09-26 07:49:55 +00:00
|
|
|
"""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
|
|
|
|
}
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
hass.async_create_task(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_OSCILLATE, data))
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
@callback
|
2018-09-26 07:49:55 +00:00
|
|
|
@bind_hass
|
2018-11-02 20:08:22 +00:00
|
|
|
def async_set_speed(hass, entity_id: str = None, speed: str = None) -> None:
|
2018-09-26 07:49:55 +00:00
|
|
|
"""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
|
|
|
|
}
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
hass.async_create_task(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_SET_SPEED, data))
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
@callback
|
2018-09-26 07:49:55 +00:00
|
|
|
@bind_hass
|
2018-11-02 20:08:22 +00:00
|
|
|
def async_set_direction(
|
|
|
|
hass, entity_id: str = None, direction: str = None) -> None:
|
2018-09-26 07:49:55 +00:00
|
|
|
"""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
|
|
|
|
}
|
|
|
|
|
2018-11-02 20:08:22 +00:00
|
|
|
hass.async_create_task(
|
|
|
|
hass.services.async_call(DOMAIN, SERVICE_SET_DIRECTION, data))
|