mirror of
https://github.com/OpenMTC/OpenMTC.git
synced 2024-12-19 21:18:00 +00:00
1052fd4a08
* Test debian stretch+python3 (#18) * changes starting with python3 explicit * removes python modules which are not available for python3 * exchanges fyzz query parsing with rdflib functionality * fixes interop tests * replaces reduce with for loop in nodb driver * simple python2 -> python3 conversions * adds changes for handling different string handling in python3 * test stretch building with travis * installing python-setuptools in docker * installing python-setuptools in docker * changing python2 to python3 in docker makefiles * changing python2 to python3 and some other test changes * push docker only in master branche * running version of openmtc * fix some port problems * porting path library completly now * restoring travis.yml * testing new travis.yml * add sudo * updating travis OS from trusty to xenial * upgrade pip before * show running docker logs * show more logs * for debugging * showlogs of docker after failure * testing new travis.yml * finish travis.yml * Adding roadmap (#26) * adding roadmap * adding a nicer view for some documents * creating contributions.md (#27) * travis only building on master branch (#25) * deleting some typo * another typo * adding a contributer * bump version to 1.3.0 * better link for contributions * Port and fix simple apps * add version tag
51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
from openmtc_app.onem2m import XAE
|
|
|
|
|
|
class SimpleDecision(XAE):
|
|
remove_registration = True
|
|
remote_cse = '/mn-cse-1/onem2m'
|
|
period = 10
|
|
|
|
def _on_register(self):
|
|
# init variables
|
|
self.switchContainers = []
|
|
# start endless loop
|
|
self.periodic_discover(self.remote_cse,
|
|
{'labels': ["openmtc:actuator_data"]},
|
|
self.period, self.handle_discovery_switch)
|
|
self.periodic_discover(self.remote_cse,
|
|
{'labels': ["openmtc:sensor_data:command"]},
|
|
self.period, self.handle_discovery_command)
|
|
self.periodic_discover(self.remote_cse,
|
|
{'labels': ["openmtc:sensor_data:brightness"]},
|
|
self.period, self.handle_discovery_brightness)
|
|
|
|
def handle_discovery_switch(self, discovery):
|
|
for uri in discovery:
|
|
self.switchContainers.append(uri)
|
|
|
|
def handle_discovery_command(self, discovery):
|
|
for uri in discovery:
|
|
self.add_container_subscription(uri, self.handle_command)
|
|
|
|
def handle_discovery_brightness(self, discovery):
|
|
for uri in discovery:
|
|
self.add_container_subscription(uri, self.handle_brightness)
|
|
|
|
def handle_command(self, container, content):
|
|
command = "ON" if content[0]['v'] == 1 else "OFF"
|
|
for switch in self.switchContainers:
|
|
self.push_content(switch, command)
|
|
|
|
def handle_brightness(self, container, content):
|
|
command = "ON" if content[0]['v'] < 500.0 else "OFF"
|
|
for switch in self.switchContainers:
|
|
self.push_content(switch, command)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from openmtc_app.flask_runner import SimpleFlaskRunner as Runner
|
|
|
|
ep = "http://localhost:8000"
|
|
Runner(SimpleDecision(poas=['http://localhost:22245'])).run(ep)
|