mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Built-in component cleanup
This commit is contained in:
parent
382c1de981
commit
4096a67251
@ -166,8 +166,8 @@ def setup(hass, config):
|
|||||||
profiles = {}
|
profiles = {}
|
||||||
|
|
||||||
for profile_path in profile_paths:
|
for profile_path in profile_paths:
|
||||||
|
if not os.path.isfile(profile_path):
|
||||||
if os.path.isfile(profile_path):
|
continue
|
||||||
with open(profile_path) as inp:
|
with open(profile_path) as inp:
|
||||||
reader = csv.reader(inp)
|
reader = csv.reader(inp)
|
||||||
|
|
||||||
@ -178,7 +178,6 @@ def setup(hass, config):
|
|||||||
for profile_id, color_x, color_y, brightness in reader:
|
for profile_id, color_x, color_y, brightness in reader:
|
||||||
profiles[profile_id] = (float(color_x), float(color_y),
|
profiles[profile_id] = (float(color_x), float(color_y),
|
||||||
int(brightness))
|
int(brightness))
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# ValueError if not 4 values per row
|
# ValueError if not 4 values per row
|
||||||
# ValueError if convert to float/int failed
|
# ValueError if convert to float/int failed
|
||||||
@ -206,7 +205,11 @@ def setup(hass, config):
|
|||||||
for light in target_lights:
|
for light in target_lights:
|
||||||
light.turn_off(**params)
|
light.turn_off(**params)
|
||||||
|
|
||||||
else:
|
if light.should_poll:
|
||||||
|
for light in target_lights:
|
||||||
|
light.update_ha_state(True)
|
||||||
|
return
|
||||||
|
|
||||||
# Processing extra data for turn light on request
|
# Processing extra data for turn light on request
|
||||||
|
|
||||||
# We process the profile first so that we get the desired
|
# We process the profile first so that we get the desired
|
||||||
|
@ -98,9 +98,7 @@ ATTR_TO_PROPERTY = [
|
|||||||
def is_on(hass, entity_id=None):
|
def is_on(hass, entity_id=None):
|
||||||
""" Returns true if specified media player entity_id is on.
|
""" Returns true if specified media player entity_id is on.
|
||||||
Will check all media player if no entity_id specified. """
|
Will check all media player if no entity_id specified. """
|
||||||
|
|
||||||
entity_ids = [entity_id] if entity_id else hass.states.entity_ids(DOMAIN)
|
entity_ids = [entity_id] if entity_id else hass.states.entity_ids(DOMAIN)
|
||||||
|
|
||||||
return any(not hass.states.is_state(entity_id, STATE_OFF)
|
return any(not hass.states.is_state(entity_id, STATE_OFF)
|
||||||
for entity_id in entity_ids)
|
for entity_id in entity_ids)
|
||||||
|
|
||||||
@ -108,28 +106,24 @@ def is_on(hass, entity_id=None):
|
|||||||
def turn_on(hass, entity_id=None):
|
def turn_on(hass, entity_id=None):
|
||||||
""" Will turn on specified media player or all. """
|
""" Will turn on specified media player or all. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||||
|
|
||||||
|
|
||||||
def turn_off(hass, entity_id=None):
|
def turn_off(hass, entity_id=None):
|
||||||
""" Will turn off specified media player or all. """
|
""" Will turn off specified media player or all. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||||
|
|
||||||
|
|
||||||
def volume_up(hass, entity_id=None):
|
def volume_up(hass, entity_id=None):
|
||||||
""" Send the media player the command for volume up. """
|
""" Send the media player the command for volume up. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_VOLUME_UP, data)
|
hass.services.call(DOMAIN, SERVICE_VOLUME_UP, data)
|
||||||
|
|
||||||
|
|
||||||
def volume_down(hass, entity_id=None):
|
def volume_down(hass, entity_id=None):
|
||||||
""" Send the media player the command for volume down. """
|
""" Send the media player the command for volume down. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_VOLUME_DOWN, data)
|
hass.services.call(DOMAIN, SERVICE_VOLUME_DOWN, data)
|
||||||
|
|
||||||
|
|
||||||
@ -156,35 +150,30 @@ def set_volume_level(hass, volume, entity_id=None):
|
|||||||
def media_play_pause(hass, entity_id=None):
|
def media_play_pause(hass, entity_id=None):
|
||||||
""" Send the media player the command for play/pause. """
|
""" Send the media player the command for play/pause. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PLAY_PAUSE, data)
|
hass.services.call(DOMAIN, SERVICE_MEDIA_PLAY_PAUSE, data)
|
||||||
|
|
||||||
|
|
||||||
def media_play(hass, entity_id=None):
|
def media_play(hass, entity_id=None):
|
||||||
""" Send the media player the command for play/pause. """
|
""" Send the media player the command for play/pause. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PLAY, data)
|
hass.services.call(DOMAIN, SERVICE_MEDIA_PLAY, data)
|
||||||
|
|
||||||
|
|
||||||
def media_pause(hass, entity_id=None):
|
def media_pause(hass, entity_id=None):
|
||||||
""" Send the media player the command for play/pause. """
|
""" Send the media player the command for play/pause. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PAUSE, data)
|
hass.services.call(DOMAIN, SERVICE_MEDIA_PAUSE, data)
|
||||||
|
|
||||||
|
|
||||||
def media_next_track(hass, entity_id=None):
|
def media_next_track(hass, entity_id=None):
|
||||||
""" Send the media player the command for next track. """
|
""" Send the media player the command for next track. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_MEDIA_NEXT_TRACK, data)
|
hass.services.call(DOMAIN, SERVICE_MEDIA_NEXT_TRACK, data)
|
||||||
|
|
||||||
|
|
||||||
def media_previous_track(hass, entity_id=None):
|
def media_previous_track(hass, entity_id=None):
|
||||||
""" Send the media player the command for prev track. """
|
""" Send the media player the command for prev track. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK, data)
|
hass.services.call(DOMAIN, SERVICE_MEDIA_PREVIOUS_TRACK, data)
|
||||||
|
|
||||||
|
|
||||||
@ -262,29 +251,30 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_MEDIA_SEEK, media_seek_service)
|
hass.services.register(DOMAIN, SERVICE_MEDIA_SEEK, media_seek_service)
|
||||||
|
|
||||||
def play_youtube_video_service(service, media_id):
|
def play_youtube_video_service(service, media_id=None):
|
||||||
""" Plays specified media_id on the media player. """
|
""" Plays specified media_id on the media player. """
|
||||||
target_players = component.extract_from_service(service)
|
if media_id is None:
|
||||||
|
service.data.get('video')
|
||||||
|
|
||||||
if media_id:
|
if media_id is None:
|
||||||
for player in target_players:
|
return
|
||||||
|
|
||||||
|
for player in component.extract_from_service(service):
|
||||||
player.play_youtube(media_id)
|
player.play_youtube(media_id)
|
||||||
|
|
||||||
if player.should_poll:
|
if player.should_poll:
|
||||||
player.update_ha_state(True)
|
player.update_ha_state(True)
|
||||||
|
|
||||||
hass.services.register(DOMAIN, "start_fireplace",
|
hass.services.register(
|
||||||
lambda service:
|
DOMAIN, "start_fireplace",
|
||||||
play_youtube_video_service(service, "eyU3bRy2x44"))
|
lambda service: play_youtube_video_service(service, "eyU3bRy2x44"))
|
||||||
|
|
||||||
hass.services.register(DOMAIN, "start_epic_sax",
|
hass.services.register(
|
||||||
lambda service:
|
DOMAIN, "start_epic_sax",
|
||||||
play_youtube_video_service(service, "kxopViU98Xo"))
|
lambda service: play_youtube_video_service(service, "kxopViU98Xo"))
|
||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_YOUTUBE_VIDEO,
|
hass.services.register(
|
||||||
lambda service:
|
DOMAIN, SERVICE_YOUTUBE_VIDEO, play_youtube_video_service)
|
||||||
play_youtube_video_service(
|
|
||||||
service, service.data.get('video')))
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -45,21 +45,18 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
def is_on(hass, entity_id=None):
|
def is_on(hass, entity_id=None):
|
||||||
""" Returns if the switch is on based on the statemachine. """
|
""" Returns if the switch is on based on the statemachine. """
|
||||||
entity_id = entity_id or ENTITY_ID_ALL_SWITCHES
|
entity_id = entity_id or ENTITY_ID_ALL_SWITCHES
|
||||||
|
|
||||||
return hass.states.is_state(entity_id, STATE_ON)
|
return hass.states.is_state(entity_id, STATE_ON)
|
||||||
|
|
||||||
|
|
||||||
def turn_on(hass, entity_id=None):
|
def turn_on(hass, entity_id=None):
|
||||||
""" Turns all or specified switch on. """
|
""" Turns all or specified switch on. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||||
|
|
||||||
|
|
||||||
def turn_off(hass, entity_id=None):
|
def turn_off(hass, entity_id=None):
|
||||||
""" Turns all or specified switch off. """
|
""" Turns all or specified switch off. """
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +81,6 @@ def setup(hass, config):
|
|||||||
switch.update_ha_state(True)
|
switch.update_ha_state(True)
|
||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_TURN_OFF, handle_switch_service)
|
hass.services.register(DOMAIN, SERVICE_TURN_OFF, handle_switch_service)
|
||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_TURN_ON, handle_switch_service)
|
hass.services.register(DOMAIN, SERVICE_TURN_ON, handle_switch_service)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user