Add bind_hass to components (#8502)
* Add bind_hass to components * Add bind_hass to group
This commit is contained in:
parent
d3be056d15
commit
d29bdddaa7
24 changed files with 138 additions and 0 deletions
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||
ATTR_CODE, ATTR_CODE_FORMAT, ATTR_ENTITY_ID, SERVICE_ALARM_TRIGGER,
|
||||
SERVICE_ALARM_DISARM, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_ARM_AWAY)
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -44,6 +45,7 @@ ALARM_SERVICE_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def alarm_disarm(hass, code=None, entity_id=None):
|
||||
"""Send the alarm the command for disarm."""
|
||||
data = {}
|
||||
|
@ -55,6 +57,7 @@ def alarm_disarm(hass, code=None, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_ALARM_DISARM, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def alarm_arm_home(hass, code=None, entity_id=None):
|
||||
"""Send the alarm the command for arm home."""
|
||||
data = {}
|
||||
|
@ -66,6 +69,7 @@ def alarm_arm_home(hass, code=None, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_ALARM_ARM_HOME, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def alarm_arm_away(hass, code=None, entity_id=None):
|
||||
"""Send the alarm the command for arm away."""
|
||||
data = {}
|
||||
|
@ -77,6 +81,7 @@ def alarm_arm_away(hass, code=None, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_ALARM_ARM_AWAY, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def alarm_trigger(hass, code=None, entity_id=None):
|
||||
"""Send the alarm the command for trigger."""
|
||||
data = {}
|
||||
|
|
|
@ -13,6 +13,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.setup import async_prepare_setup_platform
|
||||
from homeassistant.core import CoreState
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant import config as conf_util
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, CONF_PLATFORM, STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF,
|
||||
|
@ -105,6 +106,7 @@ TRIGGER_SERVICE_SCHEMA = vol.Schema({
|
|||
RELOAD_SERVICE_SCHEMA = vol.Schema({})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id):
|
||||
"""
|
||||
Return true if specified automation entity_id is on.
|
||||
|
@ -114,35 +116,41 @@ def is_on(hass, entity_id):
|
|||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id=None):
|
||||
"""Turn on specified automation or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id=None):
|
||||
"""Turn off specified automation or all."""
|
||||
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=None):
|
||||
"""Toggle specified automation or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def trigger(hass, entity_id=None):
|
||||
"""Trigger specified automation or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_TRIGGER, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def reload(hass):
|
||||
"""Reload the automation from config."""
|
||||
hass.services.call(DOMAIN, SERVICE_RELOAD)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def async_reload(hass):
|
||||
"""Reload the automation from config.
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.core import callback
|
|||
from homeassistant.const import (ATTR_ENTITY_ID, ATTR_ENTITY_PICTURE)
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
@ -55,6 +56,7 @@ CAMERA_SERVICE_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def enable_motion_detection(hass, entity_id=None):
|
||||
"""Enable Motion Detection."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
@ -62,6 +64,7 @@ def enable_motion_detection(hass, entity_id=None):
|
|||
DOMAIN, SERVICE_EN_MOTION, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def disable_motion_detection(hass, entity_id=None):
|
||||
"""Disable Motion Detection."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
|
|
@ -14,6 +14,7 @@ from numbers import Number
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.temperature import convert as convert_temperature
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -114,6 +115,7 @@ SET_SWING_MODE_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_away_mode(hass, away_mode, entity_id=None):
|
||||
"""Turn all or specified climate devices away mode on."""
|
||||
data = {
|
||||
|
@ -126,6 +128,7 @@ def set_away_mode(hass, away_mode, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_AWAY_MODE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_hold_mode(hass, hold_mode, entity_id=None):
|
||||
"""Set new hold mode."""
|
||||
data = {
|
||||
|
@ -138,6 +141,7 @@ def set_hold_mode(hass, hold_mode, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_HOLD_MODE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_aux_heat(hass, aux_heat, entity_id=None):
|
||||
"""Turn all or specified climate devices auxillary heater on."""
|
||||
data = {
|
||||
|
@ -150,6 +154,7 @@ def set_aux_heat(hass, aux_heat, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_AUX_HEAT, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_temperature(hass, temperature=None, entity_id=None,
|
||||
target_temp_high=None, target_temp_low=None,
|
||||
operation_mode=None):
|
||||
|
@ -167,6 +172,7 @@ def set_temperature(hass, temperature=None, entity_id=None,
|
|||
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, kwargs)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_humidity(hass, humidity, entity_id=None):
|
||||
"""Set new target humidity."""
|
||||
data = {ATTR_HUMIDITY: humidity}
|
||||
|
@ -177,6 +183,7 @@ def set_humidity(hass, humidity, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_HUMIDITY, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_fan_mode(hass, fan, entity_id=None):
|
||||
"""Set all or specified climate devices fan mode on."""
|
||||
data = {ATTR_FAN_MODE: fan}
|
||||
|
@ -187,6 +194,7 @@ def set_fan_mode(hass, fan, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_operation_mode(hass, operation_mode, entity_id=None):
|
||||
"""Set new target operation mode."""
|
||||
data = {ATTR_OPERATION_MODE: operation_mode}
|
||||
|
@ -197,6 +205,7 @@ def set_operation_mode(hass, operation_mode, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_OPERATION_MODE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_swing_mode(hass, swing_mode, entity_id=None):
|
||||
"""Set new target swing mode."""
|
||||
data = {ATTR_SWING_MODE: swing_mode}
|
||||
|
|
|
@ -13,6 +13,7 @@ import os
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
@ -86,24 +87,28 @@ SERVICE_TO_METHOD = {
|
|||
}
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_closed(hass, entity_id=None):
|
||||
"""Return if the cover is closed based on the statemachine."""
|
||||
entity_id = entity_id or ENTITY_ID_ALL_COVERS
|
||||
return hass.states.is_state(entity_id, STATE_CLOSED)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def open_cover(hass, entity_id=None):
|
||||
"""Open all or specified cover."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_OPEN_COVER, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def close_cover(hass, entity_id=None):
|
||||
"""Close all or specified cover."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_CLOSE_COVER, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_cover_position(hass, position, entity_id=None):
|
||||
"""Move to specific position all or specified cover."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -111,24 +116,28 @@ def set_cover_position(hass, position, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_COVER_POSITION, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def stop_cover(hass, entity_id=None):
|
||||
"""Stop all or specified cover."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_STOP_COVER, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def open_cover_tilt(hass, entity_id=None):
|
||||
"""Open all or specified cover tilt."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_OPEN_COVER_TILT, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def close_cover_tilt(hass, entity_id=None):
|
||||
"""Close all or specified cover tilt."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_CLOSE_COVER_TILT, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_cover_tilt_position(hass, tilt_position, entity_id=None):
|
||||
"""Move to specific tilt position all or specified cover."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -136,6 +145,7 @@ def set_cover_tilt_position(hass, tilt_position, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SET_COVER_TILT_POSITION, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def stop_cover_tilt(hass, entity_id=None):
|
||||
"""Stop all or specified cover tilt."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
|
|
@ -16,6 +16,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.setup import async_prepare_setup_platform
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.components import group, zone
|
||||
from homeassistant.components.discovery import SERVICE_NETGEAR
|
||||
from homeassistant.config import load_yaml_config_file, async_log_exception
|
||||
|
@ -93,6 +94,7 @@ DISCOVERY_PLATFORMS = {
|
|||
}
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass: HomeAssistantType, entity_id: str=None):
|
||||
"""Return the state if any or a specified device is home."""
|
||||
entity = entity_id or ENTITY_ID_ALL_DEVICES
|
||||
|
|
|
@ -17,6 +17,7 @@ from homeassistant.config import load_yaml_config_file
|
|||
from homeassistant.const import (SERVICE_TURN_ON, SERVICE_TOGGLE,
|
||||
SERVICE_TURN_OFF, ATTR_ENTITY_ID,
|
||||
STATE_UNKNOWN)
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
@ -118,6 +119,7 @@ SERVICE_TO_METHOD = {
|
|||
}
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id: str=None) -> bool:
|
||||
"""Return if the fans are on based on the statemachine."""
|
||||
entity_id = entity_id or ENTITY_ID_ALL_FANS
|
||||
|
@ -125,6 +127,7 @@ def is_on(hass, entity_id: str=None) -> bool:
|
|||
return state.attributes[ATTR_SPEED] not in [SPEED_OFF, STATE_UNKNOWN]
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id: str=None, speed: str=None) -> None:
|
||||
"""Turn all or specified fan on."""
|
||||
data = {
|
||||
|
@ -137,6 +140,7 @@ def turn_on(hass, entity_id: str=None, speed: str=None) -> 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 {}
|
||||
|
@ -144,6 +148,7 @@ def turn_off(hass, entity_id: str=None) -> None:
|
|||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id: str=None) -> None:
|
||||
"""Toggle all or specified fans."""
|
||||
data = {
|
||||
|
@ -153,6 +158,7 @@ def toggle(hass, entity_id: str=None) -> None:
|
|||
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 = {
|
||||
|
@ -165,6 +171,7 @@ def oscillate(hass, entity_id: str=None, should_oscillate: bool=True) -> 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 = {
|
||||
|
@ -177,6 +184,7 @@ def set_speed(hass, entity_id: str=None, speed: str=None) -> 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 = {
|
||||
|
|
|
@ -17,6 +17,7 @@ from homeassistant.const import (
|
|||
STATE_UNLOCKED, STATE_OK, STATE_PROBLEM, STATE_UNKNOWN,
|
||||
ATTR_ASSUMED_STATE, SERVICE_RELOAD)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.event import async_track_state_change
|
||||
|
@ -108,6 +109,7 @@ def _get_group_on_off(state):
|
|||
return None, None
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id):
|
||||
"""Test if the group state is in its ON-state."""
|
||||
state = hass.states.get(entity_id)
|
||||
|
@ -121,23 +123,27 @@ def is_on(hass, entity_id):
|
|||
return False
|
||||
|
||||
|
||||
@bind_hass
|
||||
def reload(hass):
|
||||
"""Reload the automation from config."""
|
||||
hass.add_job(async_reload, hass)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_reload(hass):
|
||||
"""Reload the automation from config."""
|
||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RELOAD))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_visibility(hass, entity_id=None, visible=True):
|
||||
"""Hide or shows a group."""
|
||||
data = {ATTR_ENTITY_ID: entity_id, ATTR_VISIBLE: visible}
|
||||
hass.services.call(DOMAIN, SERVICE_SET_VISIBILITY, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
||||
icon=None, view=None, control=None, add=None):
|
||||
"""Create a new user group."""
|
||||
|
@ -147,6 +153,7 @@ def set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
|||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
||||
icon=None, view=None, control=None, add=None):
|
||||
"""Create a new user group."""
|
||||
|
@ -166,18 +173,21 @@ def async_set_group(hass, object_id, name=None, entity_ids=None, visible=None,
|
|||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SET, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def remove(hass, name):
|
||||
"""Remove a user group."""
|
||||
hass.add_job(async_remove, hass, name)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_remove(hass, object_id):
|
||||
"""Remove a user group."""
|
||||
data = {ATTR_OBJECT_ID: object_id}
|
||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def expand_entity_ids(hass, entity_ids):
|
||||
"""Return entity_ids with group entity ids replaced by their members.
|
||||
|
||||
|
@ -215,6 +225,7 @@ def expand_entity_ids(hass, entity_ids):
|
|||
return found_ids
|
||||
|
||||
|
||||
@bind_hass
|
||||
def get_entity_ids(hass, entity_id, domain_filter=None):
|
||||
"""Get members of this group.
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ from homeassistant.config import load_yaml_config_file
|
|||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, CONF_NAME, CONF_ENTITY_ID)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.loader import get_component
|
||||
|
@ -59,6 +60,7 @@ SERVICE_SCAN_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def scan(hass, entity_id=None):
|
||||
"""Force process a image."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
|
|
@ -12,6 +12,7 @@ import voluptuous as vol
|
|||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, CONF_ICON, CONF_NAME, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||
SERVICE_TOGGLE, STATE_ON)
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
@ -41,21 +42,25 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id):
|
||||
"""Test if input_boolean is True."""
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id):
|
||||
"""Set input_boolean to True."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id):
|
||||
"""Set input_boolean to False."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id):
|
||||
"""Set input_boolean to False."""
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
|
||||
|
|
|
@ -10,6 +10,7 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_ICON, CONF_NAME
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
@ -77,6 +78,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
}, required=True, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_option(hass, entity_id, option):
|
||||
"""Set value of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_OPTION, {
|
||||
|
@ -85,6 +87,7 @@ def select_option(hass, entity_id, option):
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_next(hass, entity_id):
|
||||
"""Set next value of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_NEXT, {
|
||||
|
@ -92,6 +95,7 @@ def select_next(hass, entity_id):
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_previous(hass, entity_id):
|
||||
"""Set previous value of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_PREVIOUS, {
|
||||
|
@ -99,6 +103,7 @@ def select_previous(hass, entity_id):
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_options(hass, entity_id, options):
|
||||
"""Set options of input_select."""
|
||||
hass.services.call(DOMAIN, SERVICE_SET_OPTIONS, {
|
||||
|
|
|
@ -12,6 +12,7 @@ import voluptuous as vol
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, CONF_ICON, CONF_NAME)
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import async_get_last_state
|
||||
|
@ -69,6 +70,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
}, required=True, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_value(hass, entity_id, value):
|
||||
"""Set input_slider to value."""
|
||||
hass.services.call(DOMAIN, SERVICE_SELECT_VALUE, {
|
||||
|
|
|
@ -148,12 +148,14 @@ def extract_info(state):
|
|||
return params
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id=None):
|
||||
"""Return if the lights are on based on the statemachine."""
|
||||
entity_id = entity_id or ENTITY_ID_ALL_LIGHTS
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||
brightness_pct=None, rgb_color=None, xy_color=None,
|
||||
color_temp=None, kelvin=None, white_value=None,
|
||||
|
@ -193,12 +195,14 @@ def async_turn_on(hass, entity_id=None, transition=None, brightness=None,
|
|||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id=None, transition=None):
|
||||
"""Turn all or specified light off."""
|
||||
hass.add_job(async_turn_off, hass, entity_id, transition)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_turn_off(hass, entity_id=None, transition=None):
|
||||
"""Turn all or specified light off."""
|
||||
data = {
|
||||
|
@ -212,6 +216,7 @@ def async_turn_off(hass, entity_id=None, transition=None):
|
|||
DOMAIN, SERVICE_TURN_OFF, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id=None, transition=None):
|
||||
"""Toggle all or specified light."""
|
||||
data = {
|
||||
|
|
|
@ -13,6 +13,7 @@ import os
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
@ -43,12 +44,14 @@ LOCK_SERVICE_SCHEMA = vol.Schema({
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_locked(hass, entity_id=None):
|
||||
"""Return if the lock is locked based on the statemachine."""
|
||||
entity_id = entity_id or ENTITY_ID_ALL_LOCKS
|
||||
return hass.states.is_state(entity_id, STATE_LOCKED)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def lock(hass, entity_id=None, code=None):
|
||||
"""Lock all or specified locks."""
|
||||
data = {}
|
||||
|
@ -60,6 +63,7 @@ def lock(hass, entity_id=None, code=None):
|
|||
hass.services.call(DOMAIN, SERVICE_LOCK, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def unlock(hass, entity_id=None, code=None):
|
||||
"""Unlock all or specified locks."""
|
||||
data = {}
|
||||
|
|
|
@ -17,6 +17,7 @@ import async_timeout
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
@ -199,6 +200,7 @@ ATTR_TO_PROPERTY = [
|
|||
]
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id=None):
|
||||
"""
|
||||
Return true if specified media player entity_id is on.
|
||||
|
@ -210,36 +212,42 @@ def is_on(hass, entity_id=None):
|
|||
for entity_id in entity_ids)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id=None):
|
||||
"""Turn on specified media player or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id=None):
|
||||
"""Turn off specified media player or all."""
|
||||
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=None):
|
||||
"""Toggle specified media player or all."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def volume_up(hass, entity_id=None):
|
||||
"""Send the media player the command for volume up."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_VOLUME_UP, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def volume_down(hass, entity_id=None):
|
||||
"""Send the media player the command for volume down."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_VOLUME_DOWN, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def mute_volume(hass, mute, entity_id=None):
|
||||
"""Send the media player the command for muting the volume."""
|
||||
data = {ATTR_MEDIA_VOLUME_MUTED: mute}
|
||||
|
@ -250,6 +258,7 @@ def mute_volume(hass, mute, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_VOLUME_MUTE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_volume_level(hass, volume, entity_id=None):
|
||||
"""Send the media player the command for setting the volume."""
|
||||
data = {ATTR_MEDIA_VOLUME_LEVEL: volume}
|
||||
|
@ -260,42 +269,49 @@ def set_volume_level(hass, volume, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_VOLUME_SET, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_play_pause(hass, entity_id=None):
|
||||
"""Send the media player the command for play/pause."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PLAY_PAUSE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_play(hass, entity_id=None):
|
||||
"""Send the media player the command for play/pause."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PLAY, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_pause(hass, entity_id=None):
|
||||
"""Send the media player the command for pause."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PAUSE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_stop(hass, entity_id=None):
|
||||
"""Send the media player the stop command."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_MEDIA_STOP, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_next_track(hass, entity_id=None):
|
||||
"""Send the media player the command for next track."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_MEDIA_NEXT_TRACK, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_previous_track(hass, entity_id=None):
|
||||
"""Send the media player the command for prev track."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def media_seek(hass, position, entity_id=None):
|
||||
"""Send the media player the command to seek in current playing media."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
@ -303,6 +319,7 @@ def media_seek(hass, position, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_MEDIA_SEEK, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def play_media(hass, media_type, media_id, entity_id=None, enqueue=None):
|
||||
"""Send the media player the command for playing media."""
|
||||
data = {ATTR_MEDIA_CONTENT_TYPE: media_type,
|
||||
|
@ -317,6 +334,7 @@ def play_media(hass, media_type, media_id, entity_id=None, enqueue=None):
|
|||
hass.services.call(DOMAIN, SERVICE_PLAY_MEDIA, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def select_source(hass, source, entity_id=None):
|
||||
"""Send the media player the command to select input source."""
|
||||
data = {ATTR_INPUT_SOURCE: source}
|
||||
|
@ -327,12 +345,14 @@ def select_source(hass, source, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_SELECT_SOURCE, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def clear_playlist(hass, entity_id=None):
|
||||
"""Send the media player the command for clear playlist."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
hass.services.call(DOMAIN, SERVICE_CLEAR_PLAYLIST, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_shuffle(hass, shuffle, entity_id=None):
|
||||
"""Send the media player the command to enable/disable shuffle mode."""
|
||||
data = {ATTR_MEDIA_SHUFFLE: shuffle}
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.core import callback
|
|||
from homeassistant.setup import async_prepare_setup_platform
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers import template, config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect, dispatcher_send)
|
||||
|
@ -180,12 +181,14 @@ def _build_publish_data(topic, qos, retain):
|
|||
return data
|
||||
|
||||
|
||||
@bind_hass
|
||||
def publish(hass, topic, payload, qos=None, retain=None):
|
||||
"""Publish message to an MQTT topic."""
|
||||
hass.add_job(async_publish, hass, topic, payload, qos, retain)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_publish(hass, topic, payload, qos=None, retain=None):
|
||||
"""Publish message to an MQTT topic."""
|
||||
data = _build_publish_data(topic, qos, retain)
|
||||
|
@ -193,6 +196,7 @@ def async_publish(hass, topic, payload, qos=None, retain=None):
|
|||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_PUBLISH, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def publish_template(hass, topic, payload_template, qos=None, retain=None):
|
||||
"""Publish message to an MQTT topic using a template payload."""
|
||||
data = _build_publish_data(topic, qos, retain)
|
||||
|
@ -201,6 +205,7 @@ def publish_template(hass, topic, payload_template, qos=None, retain=None):
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
@bind_hass
|
||||
def async_subscribe(hass, topic, msg_callback, qos=DEFAULT_QOS,
|
||||
encoding='utf-8'):
|
||||
"""Subscribe to an MQTT topic."""
|
||||
|
@ -232,6 +237,7 @@ def async_subscribe(hass, topic, msg_callback, qos=DEFAULT_QOS,
|
|||
return async_remove
|
||||
|
||||
|
||||
@bind_hass
|
||||
def subscribe(hass, topic, msg_callback, qos=DEFAULT_QOS,
|
||||
encoding='utf-8'):
|
||||
"""Subscribe to an MQTT topic."""
|
||||
|
|
|
@ -13,6 +13,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.setup import async_prepare_setup_platform
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.const import CONF_NAME, CONF_PLATFORM
|
||||
|
@ -51,6 +52,7 @@ NOTIFY_SERVICE_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def send_message(hass, message, title=None, data=None):
|
||||
"""Send a notification message."""
|
||||
info = {
|
||||
|
|
|
@ -12,6 +12,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import TemplateError
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.util import slugify
|
||||
|
@ -43,17 +44,20 @@ DEFAULT_OBJECT_ID = 'notification'
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def create(hass, message, title=None, notification_id=None):
|
||||
"""Generate a notification."""
|
||||
hass.add_job(async_create, hass, message, title, notification_id)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def dismiss(hass, notification_id):
|
||||
"""Remove a notification."""
|
||||
hass.add_job(async_dismiss, hass, notification_id)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_create(hass, message, title=None, notification_id=None):
|
||||
"""Generate a notification."""
|
||||
data = {
|
||||
|
@ -68,6 +72,7 @@ def async_create(hass, message, title=None, notification_id=None):
|
|||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_dismiss(hass, notification_id):
|
||||
"""Remove a notification."""
|
||||
data = {ATTR_NOTIFICATION_ID: notification_id}
|
||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util import sanitize_filename
|
||||
|
||||
DOMAIN = 'python_script'
|
||||
|
@ -49,6 +50,7 @@ def setup(hass, config):
|
|||
return True
|
||||
|
||||
|
||||
@bind_hass
|
||||
def execute_script(hass, name, data=None):
|
||||
"""Execute a script."""
|
||||
filename = '{}.py'.format(name)
|
||||
|
@ -57,6 +59,7 @@ def execute_script(hass, name, data=None):
|
|||
execute(hass, filename, source, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def execute(hass, filename, source, data=None):
|
||||
"""Execute Python source."""
|
||||
from RestrictedPython import compile_restricted_exec
|
||||
|
|
|
@ -13,6 +13,7 @@ import os
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -62,12 +63,14 @@ REMOTE_SERVICE_SEND_COMMAND_SCHEMA = REMOTE_SERVICE_SCHEMA.extend({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id=None):
|
||||
"""Return if the remote is on based on the statemachine."""
|
||||
entity_id = entity_id or ENTITY_ID_ALL_REMOTES
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, activity=None, entity_id=None):
|
||||
"""Turn all or specified remote on."""
|
||||
data = {ATTR_ACTIVITY: activity}
|
||||
|
@ -76,12 +79,14 @@ def turn_on(hass, activity=None, entity_id=None):
|
|||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id=None):
|
||||
"""Turn all or specified remote off."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def send_command(hass, device, command, entity_id=None,
|
||||
num_repeats=None, delay_secs=None):
|
||||
"""Send a command to a device."""
|
||||
|
|
|
@ -11,6 +11,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, CONF_PLATFORM, SERVICE_TURN_ON)
|
||||
from homeassistant.loader import bind_hass
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
@ -56,6 +57,7 @@ SCENE_SERVICE_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def activate(hass, entity_id=None):
|
||||
"""Activate a scene."""
|
||||
data = {}
|
||||
|
|
|
@ -16,6 +16,7 @@ from homeassistant.const import (
|
|||
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON,
|
||||
SERVICE_TOGGLE, SERVICE_RELOAD, STATE_ON, CONF_ALIAS)
|
||||
from homeassistant.core import split_entity_id
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -55,16 +56,19 @@ SCRIPT_TURN_ONOFF_SCHEMA = vol.Schema({
|
|||
RELOAD_SERVICE_SCHEMA = vol.Schema({})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id):
|
||||
"""Return if the script is on based on the statemachine."""
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def reload(hass):
|
||||
"""Reload script component."""
|
||||
hass.services.call(DOMAIN, SERVICE_RELOAD)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id, variables=None):
|
||||
"""Turn script on."""
|
||||
_, object_id = split_entity_id(entity_id)
|
||||
|
@ -72,11 +76,13 @@ def turn_on(hass, entity_id, variables=None):
|
|||
hass.services.call(DOMAIN, object_id, variables)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id):
|
||||
"""Turn script on."""
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id})
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id):
|
||||
"""Toggle the script."""
|
||||
hass.services.call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id})
|
||||
|
|
|
@ -13,6 +13,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
@ -48,6 +49,7 @@ SWITCH_SERVICE_SCHEMA = vol.Schema({
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def is_on(hass, entity_id=None):
|
||||
"""Return if the switch is on based on the statemachine.
|
||||
|
||||
|
@ -57,24 +59,28 @@ def is_on(hass, entity_id=None):
|
|||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_on(hass, entity_id=None):
|
||||
"""Turn all or specified switch on."""
|
||||
hass.add_job(async_turn_on, hass, entity_id)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_turn_on(hass, entity_id=None):
|
||||
"""Turn all or specified switch on."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def turn_off(hass, entity_id=None):
|
||||
"""Turn all or specified switch off."""
|
||||
hass.add_job(async_turn_off, hass, entity_id)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_turn_off(hass, entity_id=None):
|
||||
"""Turn all or specified switch off."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
@ -82,6 +88,7 @@ def async_turn_off(hass, entity_id=None):
|
|||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def toggle(hass, entity_id=None):
|
||||
"""Toggle all or specified switch."""
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
|
|
@ -12,6 +12,7 @@ import voluptuous as vol
|
|||
from homeassistant.const import (
|
||||
ATTR_HIDDEN, ATTR_LATITUDE, ATTR_LONGITUDE, CONF_NAME, CONF_LATITUDE,
|
||||
CONF_LONGITUDE, CONF_ICON)
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.helpers import config_per_platform
|
||||
from homeassistant.helpers.entity import Entity, async_generate_entity_id
|
||||
from homeassistant.util.async import run_callback_threadsafe
|
||||
|
@ -50,6 +51,7 @@ PLATFORM_SCHEMA = vol.Schema({
|
|||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
@bind_hass
|
||||
def active_zone(hass, latitude, longitude, radius=0):
|
||||
"""Find the active zone for given latitude, longitude."""
|
||||
return run_callback_threadsafe(
|
||||
|
@ -57,6 +59,7 @@ def active_zone(hass, latitude, longitude, radius=0):
|
|||
).result()
|
||||
|
||||
|
||||
@bind_hass
|
||||
def async_active_zone(hass, latitude, longitude, radius=0):
|
||||
"""Find the active zone for given latitude, longitude.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue