From 6ad62a2ccbf42fc3c48a6d81917cc91572bf143f Mon Sep 17 00:00:00 2001 From: frittes <33233288+frittes@users.noreply.github.com> Date: Sat, 18 Nov 2017 21:12:16 +0100 Subject: [PATCH] Added cycles config option to LaMetric notifications (#10656) * Added cycles config option to lametric.py Added cycles config option, changed display_time to lifetime, code cleanup * Update lametric.py * Update lametric.py --- homeassistant/components/notify/lametric.py | 29 ++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/notify/lametric.py b/homeassistant/components/notify/lametric.py index 56030afb30c..2f967dcdda4 100644 --- a/homeassistant/components/notify/lametric.py +++ b/homeassistant/components/notify/lametric.py @@ -20,35 +20,39 @@ DEPENDENCIES = ['lametric'] _LOGGER = logging.getLogger(__name__) -CONF_DISPLAY_TIME = "display_time" +CONF_LIFETIME = "lifetime" +CONF_CYCLES = "cycles" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_ICON, default="i555"): cv.string, - vol.Optional(CONF_DISPLAY_TIME, default=10): cv.positive_int, + vol.Optional(CONF_LIFETIME, default=10): cv.positive_int, + vol.Optional(CONF_CYCLES, default=1): cv.positive_int, }) # pylint: disable=unused-variable def get_service(hass, config, discovery_info=None): - """Get the Slack notification service.""" + """Get the LaMetric notification service.""" hlmn = hass.data.get(LAMETRIC_DOMAIN) return LaMetricNotificationService(hlmn, config[CONF_ICON], - config[CONF_DISPLAY_TIME] * 1000) + config[CONF_LIFETIME] * 1000, + config[CONF_CYCLES]) class LaMetricNotificationService(BaseNotificationService): """Implement the notification service for LaMetric.""" - def __init__(self, hasslametricmanager, icon, display_time): + def __init__(self, hasslametricmanager, icon, lifetime, cycles): """Initialize the service.""" self.hasslametricmanager = hasslametricmanager self._icon = icon - self._display_time = display_time + self._lifetime = lifetime + self._cycles = cycles # pylint: disable=broad-except def send_message(self, message="", **kwargs): - """Send a message to some LaMetric deviced.""" + """Send a message to some LaMetric device.""" from lmnotify import SimpleFrame, Sound, Model from oauthlib.oauth2 import TokenExpiredError @@ -56,9 +60,10 @@ class LaMetricNotificationService(BaseNotificationService): data = kwargs.get(ATTR_DATA) _LOGGER.debug("Targets/Data: %s/%s", targets, data) icon = self._icon + cycles = self._cycles sound = None - # User-defined icon? + # Additional data? if data is not None: if "icon" in data: icon = data["icon"] @@ -73,12 +78,12 @@ class LaMetricNotificationService(BaseNotificationService): data["sound"]) text_frame = SimpleFrame(icon, message) - _LOGGER.debug("Icon/Message/Duration: %s, %s, %d", - icon, message, self._display_time) + _LOGGER.debug("Icon/Message/Cycles/Lifetime: %s, %s, %d, %d", + icon, message, self._cycles, self._lifetime) frames = [text_frame] - model = Model(frames=frames, sound=sound) + model = Model(frames=frames, cycles=cycles, sound=sound) lmn = self.hasslametricmanager.manager try: devices = lmn.get_devices() @@ -89,5 +94,5 @@ class LaMetricNotificationService(BaseNotificationService): for dev in devices: if targets is None or dev["name"] in targets: lmn.set_device(dev) - lmn.send_notification(model, lifetime=self._display_time) + lmn.send_notification(model, lifetime=self._lifetime) _LOGGER.debug("Sent notification to LaMetric %s", dev["name"])