Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

add to_json() function #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions RFXtrx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def __str__(self):
return "{0} type='{1}' id='{2}'".format(
type(self), self.type_string, self.id_string)

def to_json(self):
res = {}
for (k,v) in self.__dict__.iteritems():
if k.startswith("_"):
continue
res[ k ] = v
return res


###############################################################################
# LightingDevice class
Expand Down Expand Up @@ -214,6 +222,15 @@ class RFXtrxEvent(object):
def __init__(self, device):
self.device = device

def to_json(self):
res = {}
for (k,v) in self.__dict__.iteritems():
if k.startswith("_"):
continue
if isinstance(v, RFXtrxDevice) :
v = v.to_json()
res[ k ] = v
return res

###############################################################################
# SensorEvent class
Expand Down Expand Up @@ -259,6 +276,7 @@ def __str__(self):
type(self), self.device, sorted(self.values.items()))



###############################################################################
# ControlEvent class
###############################################################################
Expand Down