Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: feec7dfea9
...
compare: 8cb5f3dbcb
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 20, 2012
@erijo Handle error in __del__ if library isn't found 2c2ff07
Commits on Apr 01, 2012
@erijo Added simple setyp.py 8e22de1
Commits on Apr 09, 2012
@erijo Simple event tracer 8cb5f3d
Showing with 128 additions and 2 deletions.
  1. +0 −1  README.md
  2. +112 −0 bin/td_event_tracer
  3. +13 −0 setup.py
  4. +3 −1 telldus/telldus.py
View
1  README.md
@@ -14,4 +14,3 @@ TODO
* Extended the unit test for TelldusCore and friends.
* Test it with a real TellStick.
* Improve documentation.
-* Make it a proper python package.
View
112 bin/td_event_tracer
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+
+import argparse
+import sys
+
+import telldus.telldus as td
+from telldus.constants import *
+
+METHODS = {TELLSTICK_TURNON: 'turn on',
+ TELLSTICK_TURNOFF: 'turn off',
+ TELLSTICK_BELL: 'bell',
+ TELLSTICK_TOGGLE: 'toggle',
+ TELLSTICK_DIM: 'dim',
+ TELLSTICK_LEARN: 'learn',
+ TELLSTICK_EXECUTE: 'execute',
+ TELLSTICK_UP: 'up',
+ TELLSTICK_DOWN: 'down',
+ TELLSTICK_STOP: 'stop'}
+
+EVENTS = {TELLSTICK_DEVICE_ADDED: "added",
+ TELLSTICK_DEVICE_REMOVED: "removed",
+ TELLSTICK_DEVICE_CHANGED: "changed",
+ TELLSTICK_DEVICE_STATE_CHANGED: "state changed"}
+
+CHANGES = {TELLSTICK_CHANGE_NAME: "name",
+ TELLSTICK_CHANGE_PROTOCOL: "protocol",
+ TELLSTICK_CHANGE_MODEL: "model",
+ TELLSTICK_CHANGE_METHOD: "method",
+ TELLSTICK_CHANGE_AVAILABLE: "available",
+ TELLSTICK_CHANGE_FIRMWARE: "firmware"}
+
+TYPES = {TELLSTICK_CONTROLLER_TELLSTICK: 'tellstick',
+ TELLSTICK_CONTROLLER_TELLSTICK_DUO: "tellstick duo",
+ TELLSTICK_CONTROLLER_TELLSTICK_NET: "tellstick net"}
+
+def device_event(id_, method, data, cid):
+ method_string = METHODS.get(method, "UNKNOWN STATE {0}".format(method))
+ string = "[DEVICE] {0} -> {1}".format(id_, method_string)
+ if method == TELLSTICK_DIM:
+ string += " [{0}]".format(data)
+ print string
+
+def device_change_event(id_, event, type_, cid):
+ event_string = EVENTS.get(event, "UNKNOWN EVENT {0}".format(event))
+ string = "[DEVICE_CHANGE] {0} {1}".format(event_string, id_)
+ if event == TELLSTICK_DEVICE_CHANGED:
+ type_string = CHANGES.get(type_, "UNKNOWN CHANGE {0}".format(type_))
+ string += " [{0}]".format(type_string)
+ print string
+
+def raw_event(data, controller_id, cid):
+ string = "[RAW] {0} <- {1}".format(controller_id, data)
+ print string
+
+def sensor_event(protocol, model, id_, dataType, value, timestamp, cid):
+ string = "[SENSOR] {0} [{1}/{2}] ({3}) @ {4} <- {5}".format(
+ id_, protocol, model, dataType, timestamp, value)
+ print string
+
+def controller_event(id_, event, type_, new_value, cid):
+ event_string = EVENTS.get(event, "UNKNOWN EVENT {0}".format(event))
+ string = "[CONTROLLER] {0} {1}".format(event_string, id_)
+ if event == TELLSTICK_DEVICE_ADDED:
+ type_string = TYPES.get(type_, "UNKNOWN TYPE {0}".format(type_))
+ string += " {0}".format(type_string)
+ elif (event == TELLSTICK_DEVICE_CHANGED
+ or event == TELLSTICK_DEVICE_STATE_CHANGED):
+ type_string = CHANGES.get(type_, "UNKNOWN CHANGE {0}".format(type_))
+ string += " [{0}] -> {1}".format(type_string, new_value)
+ print string
+
+
+parser = argparse.ArgumentParser(description='Listen for Telldus events.')
+
+parser.add_argument(
+ '--all', action='store_true', help='Trace all events')
+parser.add_argument(
+ '--device', action='store_true', help='Trace device events')
+parser.add_argument(
+ '--change', action='store_true', help='Trace device change events')
+parser.add_argument(
+ '--raw', action='store_true', help='Trace raw events')
+parser.add_argument(
+ '--sensor', action='store_true', help='Trace sensor events')
+parser.add_argument(
+ '--controller', action='store_true', help='Trace controller events')
+
+args = parser.parse_args()
+
+core = td.TelldusCore()
+callbacks = []
+if args.device or args.all:
+ callbacks.append(core.register_device_event(device_event))
+if args.change or args.all:
+ callbacks.append(core.register_device_change_event(device_change_event))
+if args.raw or args.all:
+ callbacks.append(core.register_raw_device_event(raw_event))
+if args.sensor or args.all:
+ callbacks.append(core.register_sensor_event(sensor_event))
+if args.controller or args.all:
+ callbacks.append(core.register_controller_event(controller_event))
+
+if len(callbacks) == 0:
+ print "Must enable at least one event"
+ parser.print_usage()
+ sys.exit(1)
+
+try:
+ while True:
+ core.callbacks.process(timeout=1)
+except KeyboardInterrupt:
+ pass
View
13 setup.py
@@ -0,0 +1,13 @@
+from distutils.core import setup
+
+setup(
+ name='py-telldus',
+ version='0.1.0',
+ author='Erik Johansson',
+ author_email='erik@ejohansson.se',
+ packages=['telldus'],
+ url='https://github.com/erijo/telldus-py',
+ license='LICENSE.txt',
+ description='Python wrapper for Telldus Core',
+ long_description=open('README.md').read(),
+)
View
4 telldus/telldus.py
@@ -86,6 +86,7 @@ def unregister_all(self):
class TelldusCore(object):
def __init__(self, library_path=None, callback_manager=None):
object.__init__(self)
+ self.callbacks = None
if library_path is not None:
self.lib = Library(library_path)
@@ -98,7 +99,8 @@ def __init__(self, library_path=None, callback_manager=None):
self.callbacks = CallbackManager()
def __del__(self):
- self.callbacks.unregister_all()
+ if self.callbacks is not None:
+ self.callbacks.unregister_all()
def register_device_event(self, callback):
return self.callbacks.register_device_event(callback)

No commit comments for this range

Something went wrong with that request. Please try again.