-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add sonos alarm clock update service #7521
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e2fe5ab
Add sonos alarm clock update service
frog32 18f788d
Add tests and break lines
frog32 90cccbe
Fix style errors
frog32 639e926
Make test work with python<3.6
frog32 4175536
Fix last two pylint errors
frog32 b8e7c7a
fix new line to long errors
frog32 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 hidden or 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 |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ | |
| SERVICE_RESTORE = 'sonos_restore' | ||
| SERVICE_SET_TIMER = 'sonos_set_sleep_timer' | ||
| SERVICE_CLEAR_TIMER = 'sonos_clear_sleep_timer' | ||
| SERVICE_UPDATE_ALARM = 'sonos_update_alarm' | ||
|
|
||
| DATA_SONOS = 'sonos' | ||
|
|
||
|
|
@@ -62,6 +63,11 @@ | |
|
|
||
| # Service call validation schemas | ||
| ATTR_SLEEP_TIME = 'sleep_time' | ||
| ATTR_ALARM_ID = 'alarm_id' | ||
| ATTR_VOLUME = 'volume' | ||
| ATTR_ENABLED = 'enabled' | ||
| ATTR_INCLUDE_LINKED_ZONES = 'include_linked_zones' | ||
| ATTR_TIME = 'time' | ||
| ATTR_MASTER = 'master' | ||
| ATTR_WITH_GROUP = 'with_group' | ||
|
|
||
|
|
@@ -90,6 +96,14 @@ | |
| vol.All(vol.Coerce(int), vol.Range(min=0, max=86399)) | ||
| }) | ||
|
|
||
| SONOS_UPDATE_ALARM_SCHEMA = SONOS_SCHEMA.extend({ | ||
| vol.Required(ATTR_ALARM_ID): cv.positive_int, | ||
| vol.Optional(ATTR_TIME): cv.time, | ||
| vol.Optional(ATTR_VOLUME): cv.small_float, | ||
| vol.Optional(ATTR_ENABLED): cv.boolean, | ||
| vol.Optional(ATTR_INCLUDE_LINKED_ZONES): cv.boolean, | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the Sonos platform.""" | ||
|
|
@@ -166,6 +180,8 @@ def service_handle(service): | |
| device.set_sleep_timer(service.data[ATTR_SLEEP_TIME]) | ||
| elif service.service == SERVICE_CLEAR_TIMER: | ||
| device.clear_sleep_timer() | ||
| elif service.service == SERVICE_UPDATE_ALARM: | ||
| device.update_alarm(**service.data) | ||
|
|
||
| device.schedule_update_ha_state(True) | ||
|
|
||
|
|
@@ -193,6 +209,11 @@ def service_handle(service): | |
| DOMAIN, SERVICE_CLEAR_TIMER, service_handle, | ||
| descriptions.get(SERVICE_CLEAR_TIMER), schema=SONOS_SCHEMA) | ||
|
|
||
| hass.services.register( | ||
| DOMAIN, SERVICE_UPDATE_ALARM, service_handle, | ||
| descriptions.get(SERVICE_UPDATE_ALARM), | ||
| schema=SONOS_UPDATE_ALARM_SCHEMA) | ||
|
|
||
|
|
||
| def _parse_timespan(timespan): | ||
| """Parse a time-span into number of seconds.""" | ||
|
|
@@ -1034,6 +1055,28 @@ def clear_sleep_timer(self): | |
| """Clear the timer on the player.""" | ||
| self._player.set_sleep_timer(None) | ||
|
|
||
| @soco_error | ||
| @soco_coordinator | ||
| def update_alarm(self, **data): | ||
| """Set the alarm clock on the player.""" | ||
| from soco import alarms | ||
| a = None | ||
| for alarm in alarms.get_alarms(self.soco): | ||
| if alarm._alarm_id == str(data[ATTR_ALARM_ID]): # pylint: disable=W0212 | ||
| a = alarm | ||
| if a is None: | ||
| _LOGGER.warning("did not find alarm with id %s", data[ATTR_ALARM_ID]) | ||
|
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. line too long (81 > 79 characters) |
||
| return | ||
| if ATTR_TIME in data: | ||
| a.start_time = data[ATTR_TIME] | ||
| if ATTR_VOLUME in data: | ||
| a.volume = int(data[ATTR_VOLUME] * 100) | ||
| if ATTR_ENABLED in data: | ||
| a.enabled = data[ATTR_ENABLED] | ||
| if ATTR_INCLUDE_LINKED_ZONES in data: | ||
| a.include_linked_zones = data[ATTR_INCLUDE_LINKED_ZONES] | ||
| a.save() | ||
|
|
||
| @property | ||
| def device_state_attributes(self): | ||
| """Return device specific state attributes.""" | ||
|
|
||
This file contains hidden or 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
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.
line too long (84 > 79 characters)