Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions homeassistant/components/notify/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://home-assistant.io/components/notify.html5/
"""
import asyncio
from copy import deepcopy
import datetime
import json
import logging
Expand Down Expand Up @@ -133,17 +134,6 @@ def _load_config(filename):
return {}


class JSONBytesDecoder(json.JSONEncoder):
"""JSONEncoder to decode bytes objects to unicode."""

# pylint: disable=method-hidden
def default(self, obj):
"""Decode object if it's a bytes object, else defer to base class."""
if isinstance(obj, bytes):
return obj.decode()
return json.JSONEncoder.default(self, obj)


class HTML5PushRegistrationView(HomeAssistantView):
"""Accepts push registrations from a browser."""

Expand Down Expand Up @@ -408,8 +398,12 @@ def send_message(self, message="", **kwargs):
jwt_token = jwt.encode(jwt_claims, jwt_secret).decode('utf-8')
payload[ATTR_DATA][ATTR_JWT] = jwt_token

response = WebPusher(info[ATTR_SUBSCRIPTION]).send(
json.dumps(payload), gcm_key=self._gcm_key, ttl='86400')
# Deepcopy here because WebPusher alters our reference with byte()
# Remove deepcopy when pywebpush releases a new version (>1.4.0)
# See https://github.com/home-assistant/home-assistant/pull/11437
subscription = deepcopy(info[ATTR_SUBSCRIPTION])
response = WebPusher(subscription).send(
json.dumps(payload), gcm_key=self._gcm_key, ttl=86400)

# pylint: disable=no-member
if response.status_code == 410:
Expand Down