Changeset - 4aff3ebece7b
[Not reviewed]
refactor
0 2 0
matthewreed - 8 years ago 2017-07-28 21:55:54

Added WaterSense module and fixed some bugs
2 files changed with 27 insertions and 7 deletions:
0 comments (0 inline, 0 general)
module.py
Show inline comments
 
@@ -162,6 +162,26 @@ class RelayDriveModule(Module):
 
        self.send_message(message)
 
        self.database.log_message(self.name, message)
 

	
 
class WaterSenseModule(Module):
 
    
 
    def __init__(self, address, interface, name, database):
 
        super(WaterSenseModule, self).__init__(address, interface, name, database)
 
        
 
    
 
    def send_message(self, message):
 
        self.interface.network.send_message(message)
 
    
 
    def receive_message(self, message):
 
        self.logger.debug("Receive message! From: " + self.name)
 
        self.database.log_message(self.name, message)
 
        
 
    def update(self):
 
        pass
 
        
 
    def config(self, data_key, sensor_num, value):
 
        message = HydroBotMessage(self.uuid, (0x80 | protocol.lookup_command_key_by_name("config")), protocol.lookup_data_key_by_name(data_key), sensor_num, value)
 
        self.interface.send_message(message)
 

	
 
class UnknownModule(Module):
 
    
 
    def __init__(self, address, interface, name, database):
protocol.py
Show inline comments
 
@@ -8,7 +8,7 @@ with open('hydrobot_def.json') as def_fi
 
def lookup_device_name_by_id(id):
 
    devices = _protocol_def['devices']
 
    for device in devices:
 
        if device.get('id') == "{0:#0{1}x}".format(id, 4):
 
        if int(device.get('id'), 16) == id:
 
            return device.get('name')
 

	
 
def lookup_device_id_by_name(name):
 
@@ -20,13 +20,13 @@ def lookup_device_id_by_name(name):
 
def lookup_device_display_by_id(id):
 
    devices = _protocol_def['devices']
 
    for device in devices:
 
        if device.get('id') == "{0:#0{1}x}".format(id, 4):
 
        if int(device.get('id'), 16) == id:
 
            return device.get('display')
 
        
 
def lookup_device_class_by_id(id):
 
    devices = _protocol_def['devices']
 
    for device in devices:
 
        if device.get('id') == "{0:#0{1}x}".format(id, 4):
 
        if int(device.get('id'), 16) == id:
 
            return device.get('class')
 
        
 
def lookup_device_display_by_name(name):
 
@@ -38,7 +38,7 @@ def lookup_device_display_by_name(name):
 
def lookup_data_name_by_key(key):
 
    data_keys = _protocol_def['data_keys']
 
    for data_key in data_keys:
 
        if data_key.get('key') == "{0:#0{1}x}".format(key, 6):
 
        if int(data_key.get('key'), 16) == key:
 
            return data_key.get('name')
 

	
 
def lookup_data_key_by_name(name):
 
@@ -50,13 +50,13 @@ def lookup_data_key_by_name(name):
 
def lookup_data_display_by_key(key):
 
    data_keys = _protocol_def['data_keys']
 
    for data_key in data_keys:
 
        if data_key.get('key') == "{0:#0{1}x}".format(key, 6):
 
        if int(data_key.get('key'), 16) == key:
 
            return data_key.get('display')
 

	
 
def lookup_command_name_by_key(key):
 
    commands = _protocol_def['command_keys']
 
    for command in commands:
 
        if command.get('key') == "{0:#0{1}x}".format(key, 6):
 
        if int(data_key.get('key'), 16) == key:
 
            return command.get('name')
 

	
 
def lookup_command_key_by_name(name):
 
@@ -68,7 +68,7 @@ def lookup_command_key_by_name(name):
 
def lookup_command_display_by_key(key):
 
    commands = _protocol_def['command_keys']
 
    for command in commands:
 
        if command.get('key') == "{0:#0{1}x}".format(key, 6):
 
        if int(command.get('key'), 16) == key:
 
            return command.get('display')
 
            
 
def lookup_sensors_by_device_name(name):
0 comments (0 inline, 0 general)