def main(): # parse the command line arguments parser = argparse.ArgumentParser( description="Send a notification to LaMetric Time") parser.add_argument("msg", metavar="MESSAGE", help="The message.") parser.add_argument("--icon", "-i", default="i210", help="The icon (default: i210).") args = parser.parse_args() # create an instance of the LaMetric manager lmn = LaMetricManager() # get devices devices = lmn.get_devices() # use first device to do some tests lmn.set_device(devices[0]) # obtain all registered devices from the LaMetric cloud devices = lmn.get_devices() # select the first device for interaction lmn.set_device(devices[0]) # prepare a simple frame with an icon and some text sf = SimpleFrame(args.icon, args.msg) # prepare the model that will be send as notification model = Model(frames=[sf]) # send the notification the device lmn.send_notification(model)
def send_message(self, message="", **kwargs): """Send a message to some LaMetric device.""" from lmnotify import SimpleFrame, Sound, Model from oauthlib.oauth2 import TokenExpiredError targets = kwargs.get(ATTR_TARGET) data = kwargs.get(ATTR_DATA) _LOGGER.debug("Targets/Data: %s/%s", targets, data) icon = self._icon cycles = self._cycles sound = None # Additional data? if data is not None: if "icon" in data: icon = data["icon"] if "sound" in data: try: sound = Sound(category="notifications", sound_id=data["sound"]) _LOGGER.debug("Adding notification sound %s", data["sound"]) except AssertionError: _LOGGER.error("Sound ID %s unknown, ignoring", data["sound"]) text_frame = SimpleFrame(icon, message) _LOGGER.debug("Icon/Message/Cycles/Lifetime: %s, %s, %d, %d", icon, message, self._cycles, self._lifetime) frames = [text_frame] model = Model(frames=frames, cycles=cycles, sound=sound) lmn = self.hasslametricmanager.manager try: self._devices = lmn.get_devices() except TokenExpiredError: _LOGGER.debug("Token expired, fetching new token") lmn.get_token() self._devices = lmn.get_devices() except RequestsConnectionError: _LOGGER.warning("Problem connecting to LaMetric, " "using cached devices instead") for dev in self._devices: if targets is None or dev["name"] in targets: try: lmn.set_device(dev) lmn.send_notification(model, lifetime=self._lifetime) _LOGGER.debug("Sent notification to LaMetric %s", dev["name"]) except OSError: _LOGGER.warning("Cannot connect to LaMetric %s", dev["name"])
def main(): lmn = LaMetricManager() # get devices devices = lmn.get_devices() # use first device to do some tests lmn.set_device(devices[0]) # prepare a simple frame with an icon and some text sf = SimpleFrame("i210", "Hello World!") # prepare the model that will be send as notification model = Model(frames=[sf]) # send the notification the device lmn.send_notification(model)
def send_message(self, message="", **kwargs): """Send a message to some LaMetric deviced.""" from lmnotify import SimpleFrame, Sound, Model from oauthlib.oauth2 import TokenExpiredError targets = kwargs.get(ATTR_TARGET) data = kwargs.get(ATTR_DATA) _LOGGER.debug("Targets/Data: %s/%s", targets, data) icon = self._icon sound = None # User-defined icon? if data is not None: if "icon" in data: icon = data["icon"] if "sound" in data: try: sound = Sound(category="notifications", sound_id=data["sound"]) _LOGGER.debug("Adding notification sound %s", data["sound"]) except AssertionError: _LOGGER.error("Sound ID %s unknown, ignoring", data["sound"]) text_frame = SimpleFrame(icon, message) _LOGGER.debug("Icon/Message/Duration: %s, %s, %d", icon, message, self._display_time) frames = [text_frame] model = Model(frames=frames, sound=sound) lmn = self.hasslametricmanager.manager try: devices = lmn.get_devices() except TokenExpiredError: _LOGGER.debug("Token expired, fetching new token") lmn.get_token() devices = lmn.get_devices() 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) _LOGGER.debug("Sent notification to LaMetric %s", dev["name"])
def send_message(self, message: str = "", **kwargs: Any) -> None: """Send a message to some LaMetric device.""" targets = kwargs.get(ATTR_TARGET) data = kwargs.get(ATTR_DATA) LOGGER.debug("Targets/Data: %s/%s", targets, data) icon = self._icon cycles = self._cycles sound = None priority = self._priority icon_type = self._icon_type # Additional data? if data is not None: if "icon" in data: icon = data["icon"] if "sound" in data: try: sound = Sound(category="notifications", sound_id=data["sound"]) LOGGER.debug("Adding notification sound %s", data["sound"]) except AssertionError: LOGGER.error("Sound ID %s unknown, ignoring", data["sound"]) if "cycles" in data: cycles = int(data["cycles"]) if "icon_type" in data: if data["icon_type"] in AVAILABLE_ICON_TYPES: icon_type = data["icon_type"] else: LOGGER.warning( "Priority %s invalid, using default %s", data["priority"], priority, ) 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) LOGGER.debug( "Icon/Message/Cycles/Lifetime: %s, %s, %d, %d", icon, message, self._cycles, self._lifetime, ) frames = [text_frame] model = Model(frames=frames, cycles=cycles, sound=sound) lmn = self.hasslametricmanager.manager try: self._devices = lmn.get_devices() except TokenExpiredError: LOGGER.debug("Token expired, fetching new token") lmn.get_token() self._devices = lmn.get_devices() except RequestsConnectionError: LOGGER.warning( "Problem connecting to LaMetric, using cached devices instead") for dev in self._devices: if targets is None or dev["name"] in targets: try: lmn.set_device(dev) lmn.send_notification( model, lifetime=self._lifetime, priority=priority, icon_type=icon_type, ) LOGGER.debug("Sent notification to LaMetric %s", dev["name"]) except OSError: LOGGER.warning("Cannot connect to LaMetric %s", dev["name"])