Allow defining default turn-on values for lights in the profiles file. (#15493)

* Allow defining default turn-on values for lights in the profiles file.

* Mock out file operations in unit test.

* Fix unit test flakiness.

* Avoid unnecessary copy
This commit is contained in:
Daniel Kalmar authored and Paulus Schoutsen committed 2018-07-24 20:29:59 +02:00
1 parent 45a7ca62ae
commit 0cc9798c8f
2 files changed
+95 -1

No files matched your search

+17 -1
View File
@@ -346,7 +346,12 @@ async def async_setup(hass, config):
update_tasks = []
for light in target_lights:
if service.service == SERVICE_TURN_ON:
await light.async_turn_on(**params)
pars = params
if not pars:
pars = params.copy()
pars[ATTR_PROFILE] = Profiles.get_default(light.entity_id)
preprocess_turn_on_alternatives(pars)
await light.async_turn_on(**pars)
elif service.service == SERVICE_TURN_OFF:
await light.async_turn_off(**params)
else:
@@ -431,6 +436,17 @@ class Profiles:
"""Return a named profile."""
return cls._all.get(name)
@classmethod
def get_default(cls, entity_id):
"""Return the default turn-on profile for the given light."""
name = entity_id + ".default"
if name in cls._all:
return name
name = ENTITY_ID_ALL_LIGHTS + ".default"
if name in cls._all:
return name
return None
class Light(ToggleEntity):
"""Representation of a light."""