-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New services adaptive_lighting.turn_on
turn_off
toggle
with optional switch/lights args
#559
Open
th3w1zard1
wants to merge
11
commits into
main
Choose a base branch
from
new-service-calls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+299
−63
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d9cd74b
initial commit, passes most tests.
th3w1zard1 251babc
fixes and now passes tests
th3w1zard1 5b6ad02
Merge branch 'main' into new-service-calls
th3w1zard1 258964d
pass flake8
th3w1zard1 3b3f56f
Update test_switch.py
th3w1zard1 8dd1b56
merge origin
th3w1zard1 5f08706
Merge branch 'main' into new-service-calls
th3w1zard1 01610a3
Merge branch 'main' into new-service-calls
th3w1zard1 cfe565a
Add docs
basnijholt 295c0fa
check for cv.string
basnijholt 5fdc911
Update README
basnijholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
"""Constants for the Adaptive Lighting integration.""" | ||
|
||
from homeassistant.components.light import VALID_TRANSITION | ||
from homeassistant.const import CONF_ENTITY_ID | ||
from homeassistant.const import ( | ||
CONF_ENTITY_ID, | ||
SERVICE_TOGGLE, | ||
SERVICE_TURN_OFF, | ||
SERVICE_TURN_ON, | ||
) | ||
from homeassistant.helpers import selector | ||
import homeassistant.helpers.config_validation as cv | ||
import voluptuous as vol | ||
|
@@ -201,6 +206,19 @@ | |
'documented defaults), or "configuration" (reverts to switch config defaults). ⚙️' | ||
) | ||
|
||
CONF_WHICH_SWITCH, DEFAULT_WHICH_SWITCH = "switch_type", "main" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I imagine that "main" is not available in 99% of the installations. Should we have no default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that sounds like a good idea |
||
DOCS[CONF_WHICH_SWITCH] = ( | ||
"Which switch to target in this service call. Options: " | ||
'"main" (default, targets the main switch), "sleep", "brightness", "color"' | ||
) | ||
DOCS[SERVICE_TURN_ON] = ( | ||
"Turn on an Adaptive Lighting" " main/sleep/brightness/color switch" | ||
) | ||
DOCS[SERVICE_TURN_OFF] = ( | ||
"Turn off an Adaptive Lighting" " main/sleep/brightness/color switch" | ||
) | ||
DOCS[SERVICE_TOGGLE] = "Toggle an Adaptive Lighting main/sleep/brightness/color switch" | ||
|
||
TURNING_OFF_DELAY = 5 | ||
|
||
DOCS_MANUAL_CONTROL = { | ||
|
@@ -341,6 +359,14 @@ def apply_service_schema(initial_transition: int = 1): | |
) | ||
|
||
|
||
SERVICE_TOGGLE_SCHEMA = vol.Schema( | ||
{ | ||
vol.Optional(CONF_ENTITY_ID): cv.entity_ids, | ||
vol.Optional(CONF_LIGHTS, default=[]): cv.entity_ids, | ||
vol.Optional(CONF_WHICH_SWITCH): cv.string, | ||
} | ||
) | ||
|
||
SET_MANUAL_CONTROL_SCHEMA = vol.Schema( | ||
{ | ||
vol.Optional(CONF_ENTITY_ID): cv.entity_ids, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@th3w1zard1 could you add an explaination about what these methods can be used for?
Even I do not understand at the moment why
adaptive_lighting.apply
couldn't do most of these things 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure no worries. The main problem with AL's switches are the fact that they need to be referenced by name and not the light
With this PR we use the new format you've introduced in 1.10.1 to allow even more flexibility
I have each individual light on their own individual switch. My main use case is turning off the sleep switches when My alarm goes off. With this I can pass the light ids.
Before this I had to use a naming scheme where each switch is light.adaptive_lighting_al_my_light_entity. Then i had to learn Jinja, and substring the adaptive_lighting_al to get my switch. I have a complete tutorial on my fork's README.md if you'd like more info
This pr saves about 5 actions per script in my env
I look forward to hearing your alternatives to this!