43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
|
#!/usr/bin/env python3
|
||
|
import time
|
||
|
|
||
|
class Client:
|
||
|
def __init__(self, clientid, clienttype="default"):
|
||
|
self.clienttype = clienttype
|
||
|
self.clientid = clientid
|
||
|
|
||
|
def get_info(self):
|
||
|
return "clientid: %s, clienttype: %s" % (self.clientid, self.clienttype)
|
||
|
|
||
|
class Sensor(Client):
|
||
|
def __init__(self, sensorid, sensortype, num_values):
|
||
|
self.num_values = num_values
|
||
|
self.values = {}
|
||
|
super().__init__(sensorid, sensortype)
|
||
|
|
||
|
def get_values(self):
|
||
|
return self.values
|
||
|
|
||
|
def add_value(self, value):
|
||
|
ts = time.time()
|
||
|
self.values[ts] = value
|
||
|
|
||
|
while len(self.values) > self.num_values:
|
||
|
self.values.pop(next(iter(self.values)))
|
||
|
|
||
|
return len(self.values)
|
||
|
|
||
|
class Actor(Client):
|
||
|
def __init__(self, actorid, actortype, levels):
|
||
|
self.levels = levels
|
||
|
self.level = 0
|
||
|
super().__init__(actorid, actortype)
|
||
|
|
||
|
def get_level(self):
|
||
|
return(self.level)
|
||
|
|
||
|
def set_level(self, level):
|
||
|
if level < self.levels:
|
||
|
self.level = level
|
||
|
return(self.level)
|