-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Fix Push notifications subscription expiration/removal #7761
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3492545
Update state automation to work with new and deleted state changes
balloob d6f43ba
Version bump to 0.45.1
balloob a9926e3
Fix telegram chats (#7689)
azogue 3fb691e
Fix playback control of web streams (#7683)
cgtobi dc4b069
device_tracker.ubus: Handle empty results (#7673)
tobygray cdc8628
Allow fetching hass.io panel without auth (#7714)
balloob 6d183e8
Merge pull request #7686 from home-assistant/release-0-45-1
balloob 968697c
Fix #7758 subscription expiration/removal
hoh 12de980
Fix tests failing due to additional call
hoh d1c522c
Fix code style
hoh 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
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
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
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
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 |
|---|---|---|
|
|
@@ -115,7 +115,7 @@ def get_service(hass, config, discovery_info=None): | |
| add_manifest_json_key( | ||
| ATTR_GCM_SENDER_ID, config.get(ATTR_GCM_SENDER_ID)) | ||
|
|
||
| return HTML5NotificationService(gcm_api_key, registrations) | ||
| return HTML5NotificationService(gcm_api_key, registrations, json_path) | ||
|
|
||
|
|
||
| def _load_config(filename): | ||
|
|
@@ -327,10 +327,11 @@ def post(self, request): | |
| class HTML5NotificationService(BaseNotificationService): | ||
| """Implement the notification service for HTML5.""" | ||
|
|
||
| def __init__(self, gcm_key, registrations): | ||
| def __init__(self, gcm_key, registrations, json_path): | ||
| """Initialize the service.""" | ||
| self._gcm_key = gcm_key | ||
| self.registrations = registrations | ||
| self.registrations_json_path = json_path | ||
|
|
||
| @property | ||
| def targets(self): | ||
|
|
@@ -383,7 +384,7 @@ def send_message(self, message="", **kwargs): | |
| if not targets: | ||
| targets = self.registrations.keys() | ||
|
|
||
| for target in targets: | ||
| for target in list(targets): | ||
| info = self.registrations.get(target) | ||
| if info is None: | ||
| _LOGGER.error("%s is not a valid HTML5 push notification" | ||
|
|
@@ -399,5 +400,14 @@ def send_message(self, message="", **kwargs): | |
| jwt_token = jwt.encode(jwt_claims, jwt_secret).decode('utf-8') | ||
| payload[ATTR_DATA][ATTR_JWT] = jwt_token | ||
|
|
||
| WebPusher(info[ATTR_SUBSCRIPTION]).send( | ||
| response = WebPusher(info[ATTR_SUBSCRIPTION]).send( | ||
| json.dumps(payload), gcm_key=self._gcm_key, ttl='86400') | ||
|
|
||
| if (response.status_code == 410): | ||
| _LOGGER.info("Notification channel has expired") | ||
| reg = self.registrations.pop(target) | ||
| if not _save_config(self.registrations_json_path, self.registrations): | ||
| self.registrations[target] = reg | ||
| _LOGGER.error("Error saving registration.") | ||
| else: | ||
| _LOGGER.info("Configuration saved") | ||
|
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. no newline at end of file |
||
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
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
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
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.
line too long (86 > 79 characters)