Moved more methods out of HomeAssistant object
This commit is contained in:
1 parent
c08676aa81
commit
5835d502c7
13 files changed
+149
-111
No files matched your search
@@ -85,7 +85,7 @@ def turn_on(hass, entity_id=None, **service_data):
|
||||
if entity_id is not None:
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.call_service(ha.DOMAIN, SERVICE_TURN_ON, service_data)
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TURN_ON, service_data)
|
||||
|
||||
|
||||
def turn_off(hass, entity_id=None, **service_data):
|
||||
@@ -93,7 +93,7 @@ def turn_off(hass, entity_id=None, **service_data):
|
||||
if entity_id is not None:
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.call_service(ha.DOMAIN, SERVICE_TURN_OFF, service_data)
|
||||
hass.services.call(ha.DOMAIN, SERVICE_TURN_OFF, service_data)
|
||||
|
||||
|
||||
def extract_entity_ids(hass, service):
|
||||
@@ -195,7 +195,7 @@ def setup(hass, config):
|
||||
# ent_ids is a generator, convert it to a list.
|
||||
data[ATTR_ENTITY_ID] = list(ent_ids)
|
||||
|
||||
hass.call_service(domain, service.service, data)
|
||||
hass.services.call(domain, service.service, data)
|
||||
|
||||
hass.services.register(ha.DOMAIN, SERVICE_TURN_OFF, handle_turn_service)
|
||||
hass.services.register(ha.DOMAIN, SERVICE_TURN_ON, handle_turn_service)
|
||||
|
||||
@@ -48,56 +48,56 @@ def turn_off(hass, entity_id=None):
|
||||
""" Will turn off specified Chromecast or all. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_TURN_OFF, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
def volume_up(hass, entity_id=None):
|
||||
""" Send the chromecast the command for volume up. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_VOLUME_UP, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_VOLUME_UP, data)
|
||||
|
||||
|
||||
def volume_down(hass, entity_id=None):
|
||||
""" Send the chromecast the command for volume down. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_VOLUME_DOWN, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_VOLUME_DOWN, data)
|
||||
|
||||
|
||||
def media_play_pause(hass, entity_id=None):
|
||||
""" Send the chromecast the command for play/pause. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_PLAY_PAUSE, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_PLAY_PAUSE, data)
|
||||
|
||||
|
||||
def media_play(hass, entity_id=None):
|
||||
""" Send the chromecast the command for play/pause. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_PLAY, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_PLAY, data)
|
||||
|
||||
|
||||
def media_pause(hass, entity_id=None):
|
||||
""" Send the chromecast the command for play/pause. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_PAUSE, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_PAUSE, data)
|
||||
|
||||
|
||||
def media_next_track(hass, entity_id=None):
|
||||
""" Send the chromecast the command for next track. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_NEXT_TRACK, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_NEXT_TRACK, data)
|
||||
|
||||
|
||||
def media_prev_track(hass, entity_id=None):
|
||||
""" Send the chromecast the command for prev track. """
|
||||
data = {components.ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_PREV_TRACK, data)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_PREV_TRACK, data)
|
||||
|
||||
|
||||
# pylint: disable=too-many-locals, too-many-branches
|
||||
|
||||
@@ -92,8 +92,8 @@ def setup(hass, config):
|
||||
|
||||
# Track every time sun rises so we can schedule a time-based
|
||||
# pre-sun set event
|
||||
hass.track_state_change(sun.ENTITY_ID, schedule_light_on_sun_rise,
|
||||
sun.STATE_BELOW_HORIZON, sun.STATE_ABOVE_HORIZON)
|
||||
hass.states.track_change(sun.ENTITY_ID, schedule_light_on_sun_rise,
|
||||
sun.STATE_BELOW_HORIZON, sun.STATE_ABOVE_HORIZON)
|
||||
|
||||
# If the sun is already above horizon
|
||||
# schedule the time-based pre-sun set event
|
||||
@@ -152,12 +152,14 @@ def setup(hass, config):
|
||||
light.turn_off(hass)
|
||||
|
||||
# Track home coming of each device
|
||||
hass.track_state_change(device_entity_ids, check_light_on_dev_state_change,
|
||||
components.STATE_NOT_HOME, components.STATE_HOME)
|
||||
hass.states.track_change(
|
||||
device_entity_ids, check_light_on_dev_state_change,
|
||||
components.STATE_NOT_HOME, components.STATE_HOME)
|
||||
|
||||
# Track when all devices are gone to shut down lights
|
||||
hass.track_state_change(device_tracker.ENTITY_ID_ALL_DEVICES,
|
||||
check_light_on_dev_state_change,
|
||||
components.STATE_HOME, components.STATE_NOT_HOME)
|
||||
hass.states.track_change(
|
||||
device_tracker.ENTITY_ID_ALL_DEVICES,
|
||||
check_light_on_dev_state_change,
|
||||
components.STATE_HOME, components.STATE_NOT_HOME)
|
||||
|
||||
return True
|
||||
@@ -186,7 +186,7 @@ def setup_group(hass, name, entity_ids, user_defined=True):
|
||||
if entity_id != ent_id]):
|
||||
hass.states.set(group_entity_id, group_off, state_attr)
|
||||
|
||||
hass.track_state_change(entity_ids, update_group_state)
|
||||
hass.states.track_change(entity_ids, update_group_state)
|
||||
|
||||
hass.states.set(group_entity_id, group_state, state_attr)
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ class RequestHandler(SimpleHTTPRequestHandler):
|
||||
domain = path_match.group('domain')
|
||||
service = path_match.group('service')
|
||||
|
||||
self.server.hass.call_service(domain, service, data)
|
||||
self.server.hass.services.call(domain, service, data)
|
||||
|
||||
self._json_message("Service {}/{} called.".format(domain, service))
|
||||
|
||||
|
||||
@@ -14,32 +14,32 @@ DEPENDENCIES = []
|
||||
|
||||
def volume_up(hass):
|
||||
""" Press the keyboard button for volume up. """
|
||||
hass.call_service(DOMAIN, components.SERVICE_VOLUME_UP)
|
||||
hass.services.call(DOMAIN, components.SERVICE_VOLUME_UP)
|
||||
|
||||
|
||||
def volume_down(hass):
|
||||
""" Press the keyboard button for volume down. """
|
||||
hass.call_service(DOMAIN, components.SERVICE_VOLUME_DOWN)
|
||||
hass.services.call(DOMAIN, components.SERVICE_VOLUME_DOWN)
|
||||
|
||||
|
||||
def volume_mute(hass):
|
||||
""" Press the keyboard button for muting volume. """
|
||||
hass.call_service(DOMAIN, components.SERVICE_VOLUME_MUTE)
|
||||
hass.services.call(DOMAIN, components.SERVICE_VOLUME_MUTE)
|
||||
|
||||
|
||||
def media_play_pause(hass):
|
||||
""" Press the keyboard button for play/pause. """
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_PLAY_PAUSE)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_PLAY_PAUSE)
|
||||
|
||||
|
||||
def media_next_track(hass):
|
||||
""" Press the keyboard button for next track. """
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_NEXT_TRACK)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_NEXT_TRACK)
|
||||
|
||||
|
||||
def media_prev_track(hass):
|
||||
""" Press the keyboard button for prev track. """
|
||||
hass.call_service(DOMAIN, components.SERVICE_MEDIA_PREV_TRACK)
|
||||
hass.services.call(DOMAIN, components.SERVICE_MEDIA_PREV_TRACK)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
@@ -118,7 +118,7 @@ def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||
if xy_color:
|
||||
data[ATTR_XY_COLOR] = xy_color
|
||||
|
||||
hass.call_service(DOMAIN, SERVICE_TURN_ON, data)
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
def turn_off(hass, entity_id=None, transition=None):
|
||||
@@ -131,7 +131,7 @@ def turn_off(hass, entity_id=None, transition=None):
|
||||
if transition is not None:
|
||||
data[ATTR_TRANSITION] = transition
|
||||
|
||||
hass.call_service(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
# pylint: disable=too-many-branches, too-many-locals
|
||||
|
||||
@@ -43,14 +43,14 @@ def turn_on(hass, entity_id=None):
|
||||
""" Turns all or specified switch on. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
||||
hass.call_service(DOMAIN, SERVICE_TURN_ON, data)
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
def turn_off(hass, entity_id=None):
|
||||
""" Turns all or specified switch off. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
||||
hass.call_service(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
|
||||
Reference in new issue
Block a user