mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add priority and cycles to LaMetric (#14414)
* Add priority and cycles to LaMetric Priority can be "info", "warning" (default), or "critical" and cycles is the number of times the message is displayed. If cycles is set to 0 we get a persistent notification that has to be dismissed manually. * Fix for schema and style * Fix for style
This commit is contained in:
parent
391e3196ea
commit
8ae3caa292
@ -23,11 +23,16 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
CONF_LIFETIME = "lifetime"
|
CONF_LIFETIME = "lifetime"
|
||||||
CONF_CYCLES = "cycles"
|
CONF_CYCLES = "cycles"
|
||||||
|
CONF_PRIORITY = "priority"
|
||||||
|
|
||||||
|
AVAILABLE_PRIORITIES = ["info", "warning", "critical"]
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Optional(CONF_ICON, default="i555"): cv.string,
|
vol.Optional(CONF_ICON, default="i555"): cv.string,
|
||||||
vol.Optional(CONF_LIFETIME, default=10): cv.positive_int,
|
vol.Optional(CONF_LIFETIME, default=10): cv.positive_int,
|
||||||
vol.Optional(CONF_CYCLES, default=1): cv.positive_int,
|
vol.Optional(CONF_CYCLES, default=1): cv.positive_int,
|
||||||
|
vol.Optional(CONF_PRIORITY, default="warning"):
|
||||||
|
vol.In(AVAILABLE_PRIORITIES)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -38,18 +43,20 @@ def get_service(hass, config, discovery_info=None):
|
|||||||
return LaMetricNotificationService(hlmn,
|
return LaMetricNotificationService(hlmn,
|
||||||
config[CONF_ICON],
|
config[CONF_ICON],
|
||||||
config[CONF_LIFETIME] * 1000,
|
config[CONF_LIFETIME] * 1000,
|
||||||
config[CONF_CYCLES])
|
config[CONF_CYCLES],
|
||||||
|
config[CONF_PRIORITY])
|
||||||
|
|
||||||
|
|
||||||
class LaMetricNotificationService(BaseNotificationService):
|
class LaMetricNotificationService(BaseNotificationService):
|
||||||
"""Implement the notification service for LaMetric."""
|
"""Implement the notification service for LaMetric."""
|
||||||
|
|
||||||
def __init__(self, hasslametricmanager, icon, lifetime, cycles):
|
def __init__(self, hasslametricmanager, icon, lifetime, cycles, priority):
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
self.hasslametricmanager = hasslametricmanager
|
self.hasslametricmanager = hasslametricmanager
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
self._lifetime = lifetime
|
self._lifetime = lifetime
|
||||||
self._cycles = cycles
|
self._cycles = cycles
|
||||||
|
self._priority = priority
|
||||||
self._devices = []
|
self._devices = []
|
||||||
|
|
||||||
# pylint: disable=broad-except
|
# pylint: disable=broad-except
|
||||||
@ -64,6 +71,7 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||||||
icon = self._icon
|
icon = self._icon
|
||||||
cycles = self._cycles
|
cycles = self._cycles
|
||||||
sound = None
|
sound = None
|
||||||
|
priority = self._priority
|
||||||
|
|
||||||
# Additional data?
|
# Additional data?
|
||||||
if data is not None:
|
if data is not None:
|
||||||
@ -78,6 +86,14 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||||||
except AssertionError:
|
except AssertionError:
|
||||||
_LOGGER.error("Sound ID %s unknown, ignoring",
|
_LOGGER.error("Sound ID %s unknown, ignoring",
|
||||||
data["sound"])
|
data["sound"])
|
||||||
|
if "cycles" in data:
|
||||||
|
cycles = data['cycles']
|
||||||
|
if "priority" in data:
|
||||||
|
if data['priority'] in AVAILABLE_PRIORITIES:
|
||||||
|
priority = data['priority']
|
||||||
|
else:
|
||||||
|
_LOGGER.warning("Priority %s invalid, using default %s",
|
||||||
|
data['priority'], priority)
|
||||||
|
|
||||||
text_frame = SimpleFrame(icon, message)
|
text_frame = SimpleFrame(icon, message)
|
||||||
_LOGGER.debug("Icon/Message/Cycles/Lifetime: %s, %s, %d, %d",
|
_LOGGER.debug("Icon/Message/Cycles/Lifetime: %s, %s, %d, %d",
|
||||||
@ -100,7 +116,8 @@ class LaMetricNotificationService(BaseNotificationService):
|
|||||||
if targets is None or dev["name"] in targets:
|
if targets is None or dev["name"] in targets:
|
||||||
try:
|
try:
|
||||||
lmn.set_device(dev)
|
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",
|
_LOGGER.debug("Sent notification to LaMetric %s",
|
||||||
dev["name"])
|
dev["name"])
|
||||||
except OSError:
|
except OSError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user