Package: lmnotify
lmnotifyis a package for sending notifications toLaMetric Time. To achieve this, the package
encapsulates the REST API calls that are sent to the LaMetric device.Module InstallationThe easiest way to install thelmnotifymodule is viapip:pip install lmnotifyor clone/download this repository and install it:python3 setup.py installorpython setup.py installBasic SetupThe LaMetric Time can only be accessed by authorized applications. Therefore,
each application that wants to access the device needs to be registered
at theLaMetric Developerwebpage.Creating a Custom ApplicationThe following steps are required to register thelmnotifypython module
as new LaMetric application at their webpage:Sign Up and login to the developer webpagehttps://developer.lametric.comClick theCreatebutton in the upper right corner, then selectNotification Appand clickCreateagain.Enter an app name, a description and a redirect URLFinally, clickSaveto create the application.For the newly created app you will obtain credentials i.e. theclient idand aclient secret. Both are required in the following to to setup the
python module.BackgroundAlthough, thelmnotifypython module must be registered with the LaMetric
cloud, on the long run, there is only a very limited interaction with the cloud
necessary. The main functions of the cloud-related RESTful API deal with user
information stored at the cloud as well as the registered LaMetric devices.
Particularly, the latter is of great paramount since the list of devices
contains an API key for each device that can be used to communicate with the
device in the local network without connecting to the cloud.For that reason, the default configuration of the module will receive all
LaMetric devices from the cloud on the first call ofget_devicesand store
them in the~/.lmdevicesfile. All further calls ofget_deviceswill
simply read this file and return the devices without any interaction with the
LaMetric cloud.Configuration of the ModuleThere are three different ways to provide the LaMetric API credentials to the
module: by constructor, by environment variables or by config file.1.By constructor: Just provide theclient_idandclient_secretin
the constructor of theLaMetricManagerclass, e.g.:CLIENT_ID = "<my_client_id>"
CLIENT_SECRET = "<my_client_secret>"

lmn = LaMetricManager(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)2.By environment variables: Just set theLAMETRIC_CLIENT_IDand theLAMETRIC_CLIENT_SECRETenvironment variable, e.g. in bash:export LAMETRIC_CLIENT_ID="<my_client_id>"
export LAMETRIC_CLIENT_SECRET="<my_client_secret>"When not providing theclient_idandclient_secretin the constructor,
the environment variables will be used instead.3.By config file: The default config file is set to~/.lmconfig. When
initializing theLaMetricManagerclass without parameters the config file
will be loaded, if it is already existing. Otherwise you can set theauto_create_configparameter in the constructor to True, to create an empty
configuration file. Simply fill your credentials in the config file:[lametric]
client_id = <put the client id here>
client_secret = <put the client secret here>On the next start, the config file will be read automatically, when neitherclient_idandclient_secretare set in the constructor nor theLAMETRIC_CLIENT_IDand theLAMETRIC_CLIENT_SECRETenvironment variables
are set.As stated above in the background section, after the devices have been obtained
from the LaMetric cloud once, all further interaction can be done locally
without any interaction with the LaMetric cloud.ExampleAs simple example, let’s send a “hello world” message with an icon to the
LaMetric Time. It is assumed that you have provided the application credentials
using the environment variables or the config file so that no parameters are
set in the constructor of the LaMetricManager.from lmnotify import LaMetricManager, Model, SimpleFrame

# create an instance of the LaMetricManager
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)For more examples seehttps://github.com/keans/lmnotify/tree/master/examples.DevelopmentIf you want to contribute in the development, please check out the source code
athttps://github.com/keans/lmnotify.git.To get started with the development:git clone git@github.com:keans/lmnotify.git
cd lmnotify/
virtualenv env
source env/bin/activate
pip install -r requirements.txtFor verbose debug output simply set the logging level to debug:import logging
logging.basicConfig(level=logging.DEBUG)