From 035755154e358d707b749e4cacd4f42d161fffa4 Mon Sep 17 00:00:00 2001 From: Ronald Steinke Date: Wed, 10 Jan 2018 10:24:19 +0100 Subject: [PATCH] minor fixes and style changes for CUL868IPE --- ipes/CUL868IPE/config.json | 4 ++-- ipes/CUL868IPE/etc/conf/config.json.dist | 5 +++++ ipes/CUL868IPE/src/cul868ipe/__main__.py | 5 ++--- ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py | 11 +++++------ ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py | 11 ++++++----- ipes/CUL868IPE/src/cul868ipe/parsers.py | 2 +- ipes/CUL868IPE/src/cul868ipe/test_parsers.py | 2 -- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ipes/CUL868IPE/config.json b/ipes/CUL868IPE/config.json index d620c94..6815ee1 100644 --- a/ipes/CUL868IPE/config.json +++ b/ipes/CUL868IPE/config.json @@ -19,8 +19,8 @@ "sim_period": 3, "cul_device": "/dev/ttyACM0", "device_mappings": { - "ZBS12345678": "Fenster", - "ZBS12341234": "Dach", + "S300TH_1": "Fenster", + "S300TH_2": "Dach", "FS20_ST3_16108_1": "Wohnzimmer" }, "devices": [ diff --git a/ipes/CUL868IPE/etc/conf/config.json.dist b/ipes/CUL868IPE/etc/conf/config.json.dist index 0bd4e85..ca01ea8 100644 --- a/ipes/CUL868IPE/etc/conf/config.json.dist +++ b/ipes/CUL868IPE/etc/conf/config.json.dist @@ -18,6 +18,11 @@ "sim": false, "sim_period": 3, "cul_device": "/dev/ttyACM0", + "device_mappings": { + "S300TH_1": "Fenster", + "S300TH_2": "Dach", + "FS20_ST3_16108_1": "Wohnzimmer" + }, "devices": [ "fs20:16108-1", "fs20:16108-0" diff --git a/ipes/CUL868IPE/src/cul868ipe/__main__.py b/ipes/CUL868IPE/src/cul868ipe/__main__.py index 4ef5bce..9db206e 100644 --- a/ipes/CUL868IPE/src/cul868ipe/__main__.py +++ b/ipes/CUL868IPE/src/cul868ipe/__main__.py @@ -41,13 +41,12 @@ ssl_certs = config.get("ssl_certs", {}) s = config.get("sim", False) p = int(config.get("sim_period")) cul_device = get_value('cul_device', (unicode, str), default_device, args, config) -device_mappings = get_value('device_mappings', dict, {}, args, config) +device_mappings = get_value('device_mappings', dict, {}, args, config) devices = get_value('devices', list, [], args, config) # start app = CUL868IPE( - devices, device=cul_device, sim=s, sim_period=p, - device_mappings=device_mappings, + devices, device=cul_device, sim=s, sim_period=p, device_mappings=device_mappings, name=nm, cse_base=cb, poas=poas, originator_pre=originator_pre, **ssl_certs ) diff --git a/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py b/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py index 0d07133..e05b096 100644 --- a/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py +++ b/ipes/CUL868IPE/src/cul868ipe/cul_868_coordinator.py @@ -6,14 +6,13 @@ from random import choice from gevent import spawn from futile.logging import LoggerMixin -from .parsers import (EM1000EMParser, S300THParser, FS20Parser, HMSParser, - SIMParser) +from .parsers import (EM1000EMParser, S300THParser, FS20Parser, HMSParser, SIMParser) def _hex(n): s = hex(n)[2:] - l = len(s) - return s.zfill(l + l % 2) + len_s = len(s) + return s.zfill(len_s + len_s % 2) class CUL868Coordinator(LoggerMixin): @@ -39,9 +38,9 @@ class CUL868Coordinator(LoggerMixin): } self.sim_parsers = { - # "K": SIMParser(), + "K": SIMParser(), # "E": SIMParser(), - "F": SIMParser(), + # "F": SIMParser(), # "H": SIMParser() } diff --git a/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py b/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py index 529ec4d..e6e6068 100644 --- a/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py +++ b/ipes/CUL868IPE/src/cul868ipe/cul_868_ipe.py @@ -1,8 +1,9 @@ import time +from collections import namedtuple + +from cul_868_coordinator import CUL868Coordinator from openmtc_app.onem2m import XAE from openmtc_onem2m.model import Container -from collections import namedtuple -from cul_868_coordinator import CUL868Coordinator BAUD_RATE = 9600 NODE_DISCOVER_INTERVAL = 6 @@ -15,8 +16,8 @@ class CUL868IPE(XAE): max_nr_of_instances = 30 default_access_right = False - def __init__(self, cul_devices, device="/dev/ttyACM0", - sim=False, sim_period=3, device_mappings={}, *args, **kw): + def __init__(self, cul_devices, device="/dev/ttyACM0", sim=False, sim_period=3, + device_mappings=None, *args, **kw): super(CUL868IPE, self).__init__(*args, **kw) self.device = device @@ -37,7 +38,7 @@ class CUL868IPE(XAE): self.sim = sim self.sim_period = sim_period - self.device_mappings = device_mappings + self.device_mappings = device_mappings or {} self._old_fs20_values = {} diff --git a/ipes/CUL868IPE/src/cul868ipe/parsers.py b/ipes/CUL868IPE/src/cul868ipe/parsers.py index c87a00b..4f1f37b 100644 --- a/ipes/CUL868IPE/src/cul868ipe/parsers.py +++ b/ipes/CUL868IPE/src/cul868ipe/parsers.py @@ -30,7 +30,7 @@ class SIMParser(Parser): if line == 'K': dev_id = '1' temperature = random.uniform(0, 30) - humidity = random.uniform(0, 30) + humidity = random.uniform(5, 95) return dev_id, S300THData(temperature, humidity) elif line == 'F': dev_id = '21111111-132' + choice(['1', '2']) diff --git a/ipes/CUL868IPE/src/cul868ipe/test_parsers.py b/ipes/CUL868IPE/src/cul868ipe/test_parsers.py index 91e2174..4f6f71e 100644 --- a/ipes/CUL868IPE/src/cul868ipe/test_parsers.py +++ b/ipes/CUL868IPE/src/cul868ipe/test_parsers.py @@ -1,7 +1,5 @@ from parsers import S300THParser, EM1000EMParser, FS20Parser -__author__ = 'ren-local' - def test_parsers(): # ('1', S300THData(temperature=22.5, humidity=31.3))