class IotMqttBrokerConfig(wp_repository.RepositoryElement): """ Database mapping class for IOT broker settings. Attributes: broker_id : str Unique identification of a MQTT broker. broker_host : str IP-address or host name of the MQTT broker. broker_port : int Listening port number of the MQTT broker on "broker_host". store_date : datetime Date and time of last change in the database. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotMqttBrokerConfig() Constructor. __str__ : str Create printable character string from object. """ # pylint: disable=too-many-instance-attributes, too-few-public-methods _attribute_map = wp_repository.AttributeMap("iot_mqtt_broker", [ wp_repository.AttributeMapping( 0, "broker_id", "broker_id", str, db_key=1), wp_repository.AttributeMapping(1, "broker_host", "broker_host", str), wp_repository.AttributeMapping(2, "broker_port", "broker_port", int), wp_repository.AttributeMapping(3, "store_date", "store_date", datetime) ]) def __init__(self): """ Constructor. """ super().__init__() self.broker_id = "" self.broker_host = "localhost" self.broker_port = 1883 self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotMqttBrokerConfig({}, {}, {}, {})'.format( f'broker_id: "{self.broker_id}"', f'broker_host: {self.broker_host}"', f'broker_port: "{self.broker_port}"', f'store_date: {self.store_date_str}"')
class IotHostAssignedComponent(wp_repository.RepositoryElement): """ Database mapping class for components that are assigned to an IOT host. Attributes: host_id : str Unique identification of the IOT host. Foreign key to IotHost.host_id. comp_id : str Unique identifier of the assigned component (hardware device, sensor, etc.) process_group : int Number of the process group within which the component shall be handled. All components havint the same process_group value are started as threads within the same process. store_date : datetime Date and time of the last change in the database. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotHostAssignedComponent() Constructor. __str__: str Converts an instance of the class to a string object. """ _attribute_map = wp_repository.AttributeMap("iot_host_component", [ wp_repository.AttributeMapping(0, "host_id", "host_id", str, db_key=1), wp_repository.AttributeMapping(1, "comp_id", "comp_id", str, db_key=1), wp_repository.AttributeMapping(2, "process_group", "process_group", int), wp_repository.AttributeMapping(3, "store_date", "store_date", datetime) ]) def __init__(self): """ Constructor. """ super().__init__() self.host_id = "" self.comp_id = "" self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Converts an instance of the class to a string object. """ return 'IotHostAssignedComponent({}, {}, {}, {})'.format( f'host_id: "{self.host_id}"', f'comp_id: "{self.comp_id}"', f'process_group: "{self.process_group}"', f'store_date: "{self.store_date_str}"')
class IotRecorderGenericMsg(wp_repository.RepositoryElement): """ Model for messages received from the MQTT broker the type of which can not be identfied or that can't be converted to the corresponding message class. Attributes: msg_id : str Unique identifier of a received queueing message. msg_payload : str Payload of the received message. store_date : datetime Date and time when the record was stored in the repository. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotRecorderGenericMsg : None Constructor. __str__ : str Create printable character string from object. """ _attribute_map = wp_repository.AttributeMap( "iot_recorder_generic", [wp_repository.AttributeMapping(0, "msg_id", "msg_id", str, db_key = 1), wp_repository.AttributeMapping(1, "msg_payload", "msg_payload", str), wp_repository.AttributeMapping(2, "store_date", "store_date", datetime)]) def __init__(self, msg_id: str, msg_payload: dict): """ Constructor. """ super().__init__() self.msg_id = msg_id if msg_payload is None: self.msg_payload = "" else: self.msg_payload = json.dumps(msg_payload) self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotRecorderGenericMsg({}, {}, {})'.format( f'msg_id: "{self.msg_id}"', f'msg_payload: "{self.msg_payload}"', f'store_date: "{self.store_date_str}"')
class IotHostConfig(wp_repository.RepositoryElement): """ Database mapping class for IOT host settings. Attributes: host_id : str Unique identification of a MQTT broker. host_ip : str IP-address or host name of the MQTT broker. store_date : datetime Date and time of last change in the database. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotHost() Constructor. __str__: str Create printable character string from object. """ _attribute_map = wp_repository.AttributeMap("iot_host", [ wp_repository.AttributeMapping(0, "host_id", "host_id", str, db_key=1), wp_repository.AttributeMapping(1, "host_ip", "host_ip", str), wp_repository.AttributeMapping(2, "store_date", "store_date", datetime) ]) def __init__(self): """ Constructor. """ super().__init__() self.host_id = "" self.host_ip = "" self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotHostConfig(host_id: "{}"; host_ip: "{}"; store_date:"{}")'.format( self.host_id, self.host_ip, self.store_date_str)
class IotHardwareConfig(wp_repository.RepositoryElement): """ Database mapping class for IOT hardware components. Attributes: hardware_id : str Unique identification of an IOT hardware component. hardware_type : str Describes the type of hardware component, e.g. "ADS1115", "MCP23917". if_type : str Hardware protocol by which the component is connected ("I2C", "SPI"). i2c_bus_id : int Number of the I2C bus the hardware component is connected to. i2c_bus_address : int I2C bus address of the hardware component. polling_intervale : int Interval (in seconds) for the handler software to poll the hardware component or to poll the command queue. data_broker_id : str Unique identification of the MQTT broker to be used to publish data messages. data_topic : str Prefix for the topic to be used for publishing hardware input to the MQTT broker. input_broker_id : str Unique identification of the MQTT broker to be used to subscribe to command messages. input_topic : str Prefix for the topic to be subscribed for outputs to the hardare component. health_broker_id : str Unique identification of the MQTT broker to be used to publish health messages. health_topic : str Prefix of the topic to be used for publishing health check messages. store_date : datetime Date and time when the instance was stored in the database. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotHardwareConfig() Constructor. data_topic_full : str Retrieves the fully expanded data topic name. __str__: str Converts an instance of the class to a string object. """ # pylint: disable=too-many-instance-attributes, too-few-public-methods _attribute_map = wp_repository.AttributeMap("iot_hardware_component", [ wp_repository.AttributeMapping( 0, "device_id", "device_id", str, db_key=1), wp_repository.AttributeMapping(1, "device_type", "device_type", str), wp_repository.AttributeMapping(2, "model", "model", str), wp_repository.AttributeMapping(3, "if_type", "if_type", str), wp_repository.AttributeMapping(4, "i2c_bus_id", "i2c_bus_id", int), wp_repository.AttributeMapping(5, "i2c_bus_address", "i2c_bus_addr", int), wp_repository.AttributeMapping(6, "polling_interval", "polling_interval", int), wp_repository.AttributeMapping(7, "data_broker_id", "data_broker_id", str), wp_repository.AttributeMapping(8, "data_topic", "data_topic", str), wp_repository.AttributeMapping(9, "input_broker_id", "input_broker_id", str), wp_repository.AttributeMapping(10, "input_topic", "input_topic", str), wp_repository.AttributeMapping(11, "health_broker_id", "health_broker_id", str), wp_repository.AttributeMapping(12, "health_topic", "health_topic", str), wp_repository.AttributeMapping(13, "store_date", "store_date", datetime) ]) def __init__(self): """ Constructor. """ super().__init__() self.device_id = "" self.device_type = "" self.model = "" self.if_type = "I2C" self.i2c_bus_id = 0 self.i2c_bus_address = 0 self.polling_interval = 30 self.data_broker_id = "" self.data_topic = "hw/data" self.input_broker_id = "" self.input_topic = "hw/cmd" self.health_broker_id = "" self.health_topic = "hw/health" self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def data_topic_full(self, channel_no: int) -> str: """ Retrieves the fully expanded data topic name. Parameters: channel_no : int Channel number of the hardware device to subscribe to. Returns: The fully expanded topic name. """ return f"{self.data_topic}/{self.device_id}/{channel_no}" def __str__(self) -> str: """ Converts an instance of the class to a string object. """ return 'IotHardwareConfig({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})'.format( f'device_id: "{self.device_id}"', f'device_type: "{self.device_type}"', f'model: "{self.model}"', f'if_type: "{self.if_type}"', f'i2c_bus_id: "{self.i2c_bus_id}"', f'i2c_bus_address: "{self.i2c_bus_address}"', f'polling_interval: "{self.polling_interval}"', f'data_broker_id: "{self.data_broker_id}"', f'data_topic: "{self.data_topic}"', f'input_broker_id: "{self.input_broker_id}"', f'inpt_topic: "{self.input_topic}"', f'health_broker_id: "{self.health_broker_id}"', f'health_topic: "{self.health_topic}"', f'store_date: "{self.store_date_str}"')
class IotRecorderInputHealth(wp_repository.RepositoryElement): """ Attributes: msg_id : str Unique identifier of a received queueing message. device_type : str Type of the device that created the InputHealth message. device_id : str Unique identifier of the device that created the InputHealth message. health_time : str Date and time when the health check was executed. health_status : int Result of the health check. last_probe_time : str Date and time of the last probe message sent. num_probe_total : int Total number of input readings. num_probe_detail : list, optional Number of input readings per input channel. store_date : datetime Date and time when the record was stored in the repository. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotRecorderInputHealth : None Constructor. __str__ : str Create printable character string from object. """ # pylint: disable=too-many-instance-attributes _attribute_map = wp_repository.AttributeMap( "iot_recorder_input_health", [wp_repository.AttributeMapping(0, "msg_id", "msg_id", str, db_key = 1), wp_repository.AttributeMapping(1, "device_type", "device_type", str), wp_repository.AttributeMapping(2, "device_id", "device_id", str), wp_repository.AttributeMapping(3, "health_time", "health_time", str), wp_repository.AttributeMapping(4, "health_status", "health_status", int), wp_repository.AttributeMapping(5, "last_probe_time", "last_probe_time", str), wp_repository.AttributeMapping(6, "num_probe_total", "num_probe_total", int), wp_repository.AttributeMapping(7, "num_probe_detail", "num_probe_detail", str), wp_repository.AttributeMapping(8, "store_date", "store_date", datetime)]) def __init__(self, msg_id: str, msg: iot_msg_input.InputHealth): """ Constructor. """ super().__init__() self.msg_id = msg_id self.device_type = msg.device_type self.device_id = msg.device_id self.health_time = msg.health_time self.health_status = msg.health_status self.last_probe_time = msg.last_probe_time self.num_probe_total = msg.num_probe_total self.num_probe_detail = json.dumps(msg.num_probe_detail) self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotRecorderInputHealth({}, {}, {}, {}, {}, {}, {}, {}, {})'.format( f'msg_id: "{self.msg_id}"', f'device_type: "{self.device_type}"', f'device_id: "{self.device_id}"', f'health_time: "{self.health_time}"', f'health_status: "{self.health_status}"', f'last_probe_time: "{self.last_probe_time}"', f'num_probe_total: "{self.num_probe_total}"', f'num_probe_detail: "{self.num_probe_detail}"', f'store_date: "{self.store_date_str}"')
class IotRecorderSensorMsg(wp_repository.RepositoryElement): """ Model for "SensorMeasurement" messages received from the MQTT broker. Attributes: msg_id : str Unique identifier of a received queueing message. sensor_type : str Type of the sensor that created the measurement message. sensor_id : str Unique identifier of the sensor that created the measurement message. msmt_time : str Date and time when the measurement values were calculated. hw_value : int Input value for the sensor measurement. hw_voltage : float Measured voltage. msmt_unit : str Unit of the measurement value. msmt_value : float Calculated measurement value in the given unit. store_date : datetime Date and time when the record was stored in the repository. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotRecorderSensorMsg Constructor. __str__ : str Create printable character string from object. """ # pylint: disable=too-many-instance-attributes _attribute_map = wp_repository.AttributeMap( "iot_recorder_sensor_msmt", [wp_repository.AttributeMapping(0, "msg_id", "msg_id", str, db_key = 1), wp_repository.AttributeMapping(1, "sensor_type", "sensor_type", str), wp_repository.AttributeMapping(2, "sensor_id", "sensor_id", str), wp_repository.AttributeMapping(3, "msmt_time", "msmt_time", str), wp_repository.AttributeMapping(4, "hw_value", "hw_value", int), wp_repository.AttributeMapping(5, "hw_voltage", "hw_voltage", float), wp_repository.AttributeMapping(6, "msmt_unit", "msmt_unit", str), wp_repository.AttributeMapping(7, "msmt_value", "msmt_value", float), wp_repository.AttributeMapping(8, "store_date", "store_date", datetime)]) def __init__(self, msg_id: str, msg: iot_msg_sensor.SensorMsmt): """ Constructor. Parameters: msg_id : str Unique identifier of the received QueueMessage. msg : iot_msg_sensor.SensorMeasurement Payload of the received QueueMessage to be stored in the repository. """ self.msg_id = msg_id self.sensor_type = msg.sensor_type self.sensor_id = msg.sensor_id self.msmt_time = msg.msmt_time self.hw_value = msg.hw_value self.hw_voltage = msg.hw_voltage self.msmt_unit = msg.msmt_unit self.msmt_value = msg.msmt_value self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotRecorderSensorMsg({} {} {} {} {} {} {} {} {})'.format( f'msg_id: "{self.msg_id}"', f'sensor_type: "{self.sensor_type}"', f'sensor_id: "{self.sensor_id}"', f'msmt_time: "{self.msmt_time}"', f'hw_value: "{self.hw_value}"', f'hw_voltage: "{self.hw_voltage:.5f}"', f'msmt_unit: "{self.msmt_unit}"', f'msmt_value: "{self.msmt_value:.2f}"', f'store_date: "{self.store_date_str}"')
class IotRecorderMsg(wp_repository.RepositoryElement): """ Model for the general part of received messages to be stored in a repository. Derived from wp_repository.RepositoryElement. Attributes: msg_id : str Unique identifier of a received queueing message. msg_topic : str Topic from which the message was retrieved. msg_timestamp : str Date and time when the message was published. msg_class : str Class name of the message payload. store_date : datetime Date and time when the record was stored in the repository. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotRecorderMsg : None Constructor. __str__ : str Create printable character string from object. """ _attribute_map = wp_repository.AttributeMap( "iot_recorder_msg", [wp_repository.AttributeMapping(0, "msg_id", "msg_id", str, db_key = 1), wp_repository.AttributeMapping(1, "msg_topic", "msg_topic", str), wp_repository.AttributeMapping(2, "msg_timestamp", "msg_timestamp", str), wp_repository.AttributeMapping(3, "msg_class", "msg_class", str), wp_repository.AttributeMapping(4, "store_date", "store_date", datetime)]) def __init__(self, qmsg: wp_queueing.QueueMessage = None): """ Constructor. """ super().__init__() if qmsg is None: self.msg_id = "" self.msg_topic = "" self.msg_timestamp = None else: self.msg_id = qmsg.msg_id self.msg_topic = qmsg.msg_topic self.msg_timestamp = qmsg.msg_timestamp self.msg_class = "" self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotRecorderMsg({}, {}, {}, {})'.format( f'msg_id: "{self.msg_id}"', f'msg_topic: "{self.msg_topic}"', f'msg_timestamp: "{self.msg_timestamp}"', f'store_date: "{self.store_date_str}"')
class IotRecorderInputProbe(wp_repository.RepositoryElement): """ Model for "InputProbe" messages received from the MQTT broker. Attributes: msg_id : str Unique identifier of a received queueing message. device_type : str Type of the device that created the InputProble message. device_id : str Unique identifier of the device that created the InputProbe message. probe_time : str Date and time when the InputProbe message was generated. channel_no : int Number of the input channel read for the probe. value : int Value read from the input channel. voltage : float Voltage detected on the input channel. store_date : datetime Date and time when the record was stored in the repository. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotRecorderInputProbe : None Constructor. __str__ : str Create printable character string from object. """ # pylint: disable=too-many-instance-attributes _attribute_map = wp_repository.AttributeMap( "iot_recorder_input_probe", [wp_repository.AttributeMapping(0, "msg_id", "msg_id", str, db_key = 1), wp_repository.AttributeMapping(1, "device_type", "device_type", str), wp_repository.AttributeMapping(2, "device_id", "device_id", str), wp_repository.AttributeMapping(3, "probe_time", "probe_time", str), wp_repository.AttributeMapping(4, "channel_no", "channel_no", int), wp_repository.AttributeMapping(5, "value", "value", int), wp_repository.AttributeMapping(6, "voltage", "voltage", float), wp_repository.AttributeMapping(7, "store_date", "store_date", datetime)]) def __init__(self, msg_id: str, msg: iot_msg_input.InputProbe): """ Constructor. """ self.msg_id = msg_id self.device_type = msg.device_type self.device_id = msg.device_id self.probe_time = msg.probe_time self.channel_no = msg.channel_no self.value = msg.value self.voltage = msg.voltage self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotRecorderInputProbe({}, {}, {}, {}, {}, {}, {}, {})'.format( f'msg_id: "{self.msg_id}"', f'device_type: "{self.device_type}"', f'device_id: "{self.device_id}"', f'probe_time: "{self.probe_time}"', f'channel_no: "{self.channel_no}"', f'value: "{self.value}"', f'voltage: "{self.voltage:.5f}"', f'store_date: "{self.store_date_str}"')
class IotSensorConfig(wp_repository.RepositoryElement): """ Database mapping class for IOT sensors. Attributes: sensor_id : str Unique identification of the IOT sensor. broker_id : str Unique identification of the MQTT broker to be used to publish and subscribe to messages. sensor_type : str Type of the sensor. device_id : str Unique identification of the hardware component the IOT sensor is connected to. hw_channel : int Number of the input channel of the hardware component the IOT sensor is connected to. polling_interval : int Interval (in seconds) for polling the MQTT for messages on the input queue. store_date : str Date and time when the object was stored in the database. Properties: store_date_str : str Getter for the last change date and time as string. Methods: IotSensorConfig() Constructor. __str__ : str Create printable character string from object. """ # pylint: disable=too-many-instance-attributes, too-few-public-methods _attribute_map = wp_repository.AttributeMap("iot_sensor", [ wp_repository.AttributeMapping( 0, "sensor_id", "sensor_id", str, db_key=1), wp_repository.AttributeMapping(1, "sensor_type", "sensor_type", str), wp_repository.AttributeMapping(2, "device_id", "device_id", str), wp_repository.AttributeMapping(3, "device_channel", "hw_channel", int), wp_repository.AttributeMapping(4, "polling_interval", "polling_interval", int), wp_repository.AttributeMapping(5, "data_broker_id", "data_broker_id", str), wp_repository.AttributeMapping(6, "data_topic", "data_topic", str), wp_repository.AttributeMapping(7, "health_broker_id", "health_broker_id", str), wp_repository.AttributeMapping(8, "health_topic", "health_topic", str), wp_repository.AttributeMapping(9, "store_date", "store_date", datetime) ]) def __init__(self): """ Constructor. """ super().__init__() self.sensor_id = "" self.sensor_type = "" self.device_id = "" self.device_channel = 0 self.polling_interval = 15 self.input_broker_id = "" self.input_topic = "sensor/input" self.data_broker_id = "" self.data_topic = "sensor/data" self.health_broker_id = "" self.health_topic = "sensor/health" self.store_date = datetime.now() @property def store_date_str(self) -> str: """ Getter for the last change date and time as string. Returns: store_date converted to a string. """ return self.store_date.strftime("%Y-%m-%d %H:%M:%S") def __str__(self) -> str: """ Create printable character string from object. """ return 'IotSensorConfig({}, {}, {}, {}, {}, {}, {}, {}, {}, {})'.format( f'sensor_id: "{self.sensor_id}"', f'sensor_type: "{self.sensor_type}"', f'device_id: "{self.device_id}"', f'device_channel: "{self.device_channel}"', f'polling_interval: "{self.polling_interval}"', f'data_broker_id: "{self.data_broker_id}"', f'data-topic: "{self.data_topic}"', f'health_broker_id: "{self.health_broker_id}"', f'health_topic: "{self.health_topic}"', f'store_date: "{self.store_date_str}"')