mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Light/Switch/Thermostat: use new extract_from_service helper
This commit is contained in:
parent
72b930af8f
commit
68668fc658
@ -57,7 +57,6 @@ from homeassistant.helpers.device_component import DeviceComponent
|
|||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
||||||
from homeassistant.helpers import extract_entity_ids
|
|
||||||
from homeassistant.components import group, discovery, wink
|
from homeassistant.components import group, discovery, wink
|
||||||
|
|
||||||
|
|
||||||
@ -146,8 +145,6 @@ def setup(hass, config):
|
|||||||
GROUP_NAME_ALL_LIGHTS)
|
GROUP_NAME_ALL_LIGHTS)
|
||||||
component.setup(config)
|
component.setup(config)
|
||||||
|
|
||||||
lights = component.devices
|
|
||||||
|
|
||||||
# Load built-in profiles and custom profiles
|
# Load built-in profiles and custom profiles
|
||||||
profile_paths = [os.path.join(os.path.dirname(__file__),
|
profile_paths = [os.path.join(os.path.dirname(__file__),
|
||||||
LIGHT_PROFILES_FILE),
|
LIGHT_PROFILES_FILE),
|
||||||
@ -182,12 +179,7 @@ def setup(hass, config):
|
|||||||
dat = service.data
|
dat = service.data
|
||||||
|
|
||||||
# Convert the entity ids to valid light ids
|
# Convert the entity ids to valid light ids
|
||||||
target_lights = [lights[entity_id] for entity_id
|
target_lights = component.extract_from_service(service)
|
||||||
in extract_entity_ids(hass, service)
|
|
||||||
if entity_id in lights]
|
|
||||||
|
|
||||||
if not target_lights:
|
|
||||||
target_lights = lights.values()
|
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ from homeassistant.helpers.device_component import DeviceComponent
|
|||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
|
||||||
from homeassistant.helpers import extract_entity_ids
|
|
||||||
from homeassistant.components import group, discovery, wink
|
from homeassistant.components import group, discovery, wink
|
||||||
|
|
||||||
DOMAIN = 'switch'
|
DOMAIN = 'switch'
|
||||||
@ -64,16 +63,9 @@ def setup(hass, config):
|
|||||||
GROUP_NAME_ALL_SWITCHES)
|
GROUP_NAME_ALL_SWITCHES)
|
||||||
component.setup(config)
|
component.setup(config)
|
||||||
|
|
||||||
switches = component.devices
|
|
||||||
|
|
||||||
def handle_switch_service(service):
|
def handle_switch_service(service):
|
||||||
""" Handles calls to the switch services. """
|
""" Handles calls to the switch services. """
|
||||||
target_switches = [switches[entity_id] for entity_id
|
target_switches = component.extract_from_service(service)
|
||||||
in extract_entity_ids(hass, service)
|
|
||||||
if entity_id in switches]
|
|
||||||
|
|
||||||
if not target_switches:
|
|
||||||
target_switches = switches.values()
|
|
||||||
|
|
||||||
for switch in target_switches:
|
for switch in target_switches:
|
||||||
if service.service == SERVICE_TURN_ON:
|
if service.service == SERVICE_TURN_ON:
|
||||||
|
@ -56,18 +56,11 @@ def setup(hass, config):
|
|||||||
component = DeviceComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
component = DeviceComponent(_LOGGER, DOMAIN, hass, SCAN_INTERVAL)
|
||||||
component.setup(config)
|
component.setup(config)
|
||||||
|
|
||||||
thermostats = component.devices
|
|
||||||
|
|
||||||
def thermostat_service(service):
|
def thermostat_service(service):
|
||||||
""" Handles calls to the services. """
|
""" Handles calls to the services. """
|
||||||
|
|
||||||
# Convert the entity ids to valid light ids
|
# Convert the entity ids to valid light ids
|
||||||
target_thermostats = [thermostats[entity_id] for entity_id
|
target_thermostats = component.extract_from_service(service)
|
||||||
in extract_entity_ids(hass, service)
|
|
||||||
if entity_id in thermostats]
|
|
||||||
|
|
||||||
if not target_thermostats:
|
|
||||||
target_thermostats = thermostats.values()
|
|
||||||
|
|
||||||
if service.service == SERVICE_SET_AWAY_MODE:
|
if service.service == SERVICE_SET_AWAY_MODE:
|
||||||
away_mode = service.data.get(ATTR_AWAY_MODE)
|
away_mode = service.data.get(ATTR_AWAY_MODE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user