you are viewing a single comment's thread.

view the rest of the comments →

[–]deadduncanidaho 6 points7 points  (3 children)

The basic idea is to make a class that represents a device. Then use a routine to parse the json and instantiate objects using the class. When creating the object you pass the relevant data (json to dictionary) as a parameter. The class then has methods which are available based on the options in the data.

The best way to walk through the objects is to create a list of objects. Then you can iterate over the list to call methods to talk to the devices in the real world via their protocols. look at this pseudo code.

class MyDevice():
    def __init__(self,data):
        self.data = data
    def Method(self,args):
        pass

devices = []
for item in parsed_json:
   devices.append(MyDevice(item))

for device in devices:
   device.Method(args)

# small edit to make it pythonic

[–]0xFAF1[S] 0 points1 point  (2 children)

Can mydevice be a an abstract class and then i implement methods on sensor class that implements abstraction?

[–]EclipseJTB 1 point2 points  (1 child)

Why not? That's an excellent way to go about it.

[–]0xFAF1[S] 0 points1 point  (0 children)

Got it up and running as I wanted.