Skip to content
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

Add Gotify component #53050

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1c0b66a
Add Gotify component. Update CODEOWNERS and .coveragerc for new compo…
benjmarshall Jul 14, 2021
4581a82
Update homeassistant/components/gotify/manifest.json
benjmarshall Jul 30, 2021
fee256f
Update old function name
benjmarshall Jul 30, 2021
a4bc041
Use external library for service communication
benjmarshall Jul 30, 2021
4532ed1
Migrate component to config flow.
benjmarshall Aug 1, 2021
135ff81
Simplify ConfigFlow
milanmeu Aug 1, 2021
283d95e
Merge pull request #5 from milanmeu/patch-9
benjmarshall Aug 2, 2021
5c610f3
Update tests to be compatible with simplified config flow
benjmarshall Aug 2, 2021
e60f4d0
Merge pull request #6 from benjmarshall/gotify_config_flow
benjmarshall Aug 2, 2021
c53b8a5
Remove unused strings.
benjmarshall Aug 2, 2021
537b537
Fix and update translation strings
benjmarshall Aug 2, 2021
99825bc
Fix calling discovery for Notification platform. Fix creation of spec…
benjmarshall Aug 3, 2021
02654ad
Update interaction with gotify lib to use new class support
benjmarshall Aug 4, 2021
f4bd2b5
Fix default form input.
benjmarshall Aug 4, 2021
d3e02cb
Update tests to match updated config flow
benjmarshall Aug 4, 2021
3ee71d2
Change class to cloud_polling
benjmarshall Aug 4, 2021
ca2cf85
Add unload function to remove notify service when config entry is rem…
benjmarshall Aug 4, 2021
632f84e
Update setup and unload functions with suggested changes from review
benjmarshall Aug 4, 2021
29ef3f8
Use entry_id as ID to store config against. Re-work initial configura…
benjmarshall Jan 17, 2022
eaa96e2
Remove print statement.
benjmarshall Jan 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -380,6 +380,7 @@ omit =
homeassistant/components/google_travel_time/__init__.py
homeassistant/components/google_travel_time/helpers.py
homeassistant/components/google_travel_time/sensor.py
homeassistant/components/gotify/notify.py
homeassistant/components/gpmdp/media_player.py
homeassistant/components/gpsd/sensor.py
homeassistant/components/greeneye_monitor/*
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -190,6 +190,7 @@ homeassistant/components/goalzero/* @tkdrob
homeassistant/components/gogogate2/* @vangorra @bdraco
homeassistant/components/google_assistant/* @home-assistant/cloud
homeassistant/components/google_cloud/* @lufton
homeassistant/components/gotify/* @benjmarshall
homeassistant/components/gpsd/* @fabaff
homeassistant/components/gree/* @cmroche
homeassistant/components/greeneye_monitor/* @jkeljo
Expand Down
24 changes: 24 additions & 0 deletions homeassistant/components/gotify/__init__.py
@@ -0,0 +1,24 @@
"""The gotify component."""
import voluptuous as vol

from homeassistant.const import CONF_TOKEN, CONF_URL
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv

from .const import DOMAIN

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{vol.Required(CONF_TOKEN): cv.string, vol.Required(CONF_URL): cv.string}
)
},
extra=vol.ALLOW_EXTRA,
)
benjmarshall marked this conversation as resolved.
Show resolved Hide resolved


def setup(hass, config):
"""Set up the gotify component."""
hass.data[DOMAIN] = config[DOMAIN]
discovery.load_platform(hass, "notify", DOMAIN, {}, config)
return True
benjmarshall marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions homeassistant/components/gotify/const.py
@@ -0,0 +1,3 @@
"""Const for gotify."""

DOMAIN = "gotify"
8 changes: 8 additions & 0 deletions homeassistant/components/gotify/manifest.json
@@ -0,0 +1,8 @@
{
"domain": "gotify",
"name": "Gotify",
"documentation": "https://www.home-assistant.io/integrations/gotify",
"codeowners": ["@benjmarshall"],
"iot_class": "cloud_push",
"requirements": ["gotify==0.1.1"]
}
62 changes: 62 additions & 0 deletions homeassistant/components/gotify/notify.py
@@ -0,0 +1,62 @@
"""Gotify platform for notify component."""
import logging

import gotify

from homeassistant.components.notify import (
ATTR_DATA,
ATTR_TITLE,
BaseNotificationService,
)
from homeassistant.const import CONF_TOKEN, CONF_URL

from .const import DOMAIN

ATTR_LEVEL = "level"
ATTR_PRIORITY = "priority"
ATTR_TOKEN = "token"
ATTR_URL = "url"
ATTR_LINK = "link"

_LOGGER = logging.getLogger(__name__)


def get_service(hass, config, discovery_info=None):
"""Get the Gotify notification service."""
return GotifyNotificationService(
hass.data[DOMAIN][CONF_TOKEN], hass.data[DOMAIN][CONF_URL]
)


class GotifyNotificationService(BaseNotificationService):
"""Implement the notification service for Gotify."""

def __init__(self, token, url):
"""Initialize the service."""
self.token = token
self.url = url
gotify.config(
base_url=url,
app_token=token,
)

def send_message(self, message, **kwargs):
"""Send a message."""
data = kwargs.get(ATTR_DATA) or {}
title = kwargs.get(ATTR_TITLE) or None
priority = data.get(ATTR_PRIORITY) or 4
link = data.get(ATTR_LINK) or ""

extras = {
"client::display": {"contentType": "text/markdown"},
"client::notification": {
"click": {"url": "homeassistant://navigate/" + link}
},
}

try:
gotify.create_message(
message, title=title, priority=priority, extras=extras
)
except gotify.GotifyError as exception:
_LOGGER.error("Send message failed: %s", str(exception))
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -708,6 +708,9 @@ googlemaps==2.5.1
# homeassistant.components.slide
goslide-api==0.5.1

# homeassistant.components.gotify
gotify==0.1.1

# homeassistant.components.remote_rpi_gpio
gpiozero==1.5.1

Expand Down