Skip to content
Merged
Changes from 1 commit
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: 17 additions & 3 deletions homeassistant/components/notify/lametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

CONF_LIFETIME = "lifetime"
CONF_CYCLES = "cycles"
CONF_PRIORITY = "priority"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_ICON, default="i555"): cv.string,
vol.Optional(CONF_LIFETIME, default=10): cv.positive_int,
vol.Optional(CONF_CYCLES, default=1): cv.positive_int,
vol.Optional(CONF_PRIORITY, default="warning"): cv.string,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVAILABLE_PRIORITIES = ["info", "warning", "critical"]
...
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
...
    vol.Optional(CONF_PRIORITY, default="warning"):
        vol.In(AVAILABLE_PRIORITIES),
})

})


Expand All @@ -38,18 +40,20 @@ def get_service(hass, config, discovery_info=None):
return LaMetricNotificationService(hlmn,
config[CONF_ICON],
config[CONF_LIFETIME] * 1000,
config[CONF_CYCLES])
config[CONF_CYCLES],
config[CONF_PRIORITY])


class LaMetricNotificationService(BaseNotificationService):
"""Implement the notification service for LaMetric."""

def __init__(self, hasslametricmanager, icon, lifetime, cycles):
def __init__(self, hasslametricmanager, icon, lifetime, cycles, priority):
"""Initialize the service."""
self.hasslametricmanager = hasslametricmanager
self._icon = icon
self._lifetime = lifetime
self._cycles = cycles
self._priority = priority
self._devices = []

# pylint: disable=broad-except
Expand All @@ -64,6 +68,7 @@ def send_message(self, message="", **kwargs):
icon = self._icon
cycles = self._cycles
sound = None
priority = self._priority

# Additional data?
if data is not None:
Expand All @@ -78,6 +83,14 @@ def send_message(self, message="", **kwargs):
except AssertionError:
_LOGGER.error("Sound ID %s unknown, ignoring",
data["sound"])
if "cycles" in data:
cycles = data['cycles']
if "priority" in data:
if data['priority'] in ["info", "warning", "critical"]:
priority = data['priority']
else:
_LOGGER.warning("Priority '%s' invalid, using default "
"'%s'" % (data['priority'], priority))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't put additional quotes around the priority variables:
https://developers.home-assistant.io/docs/en/development_guidelines.html#log-messages

Pass the priority variables as parameters:

_LOGGER.warning("Priority %s blabla %s", data['priority'], priority)


text_frame = SimpleFrame(icon, message)
_LOGGER.debug("Icon/Message/Cycles/Lifetime: %s, %s, %d, %d",
Expand All @@ -100,7 +113,8 @@ def send_message(self, message="", **kwargs):
if targets is None or dev["name"] in targets:
try:
lmn.set_device(dev)
lmn.send_notification(model, lifetime=self._lifetime)
lmn.send_notification(model, lifetime=self._lifetime,
priority=priority)
_LOGGER.debug("Sent notification to LaMetric %s",
dev["name"])
except OSError:
Expand Down