def get_sensors(self) -> List[Sensor]: sensors_data = self.get(self.__REDIS_SENSORS_KEY) sensors = [] for sensor_data in sensors_data: sensor = Sensor(sensor_data['id'], sensor_data['type'], sensor_data['location'], sensor_data['value']) if 'name' in sensor_data: sensor.name = sensor_data['name'] if 'communication_code' in sensor_data: sensor.communication_code = sensor_data['communication_code'] else: sensor.communication_code = (False, False) if 'last_updated' in sensor_data: sensor.last_updated = sensor_data['last_updated'] else: sensor.last_updated = 0 sensors.append(sensor) return sensors
def __update_zwave_sensor(self, sensor: Sensor): new_value = self.__zwave_device.get_sensor_value(sensor.id) self.__logger.info("New value for sensor with id {0} is {1}: ".format( sensor.id, new_value)) if None is not new_value: sensor.value = round(new_value, 1) sensor.last_updated = calendar.timegm(datetime.now().timetuple()) self.__sensors_repo.set_sensor(sensor) dispatcher.send(SensorUpdateEvent.NAME, event=SensorUpdateEvent(sensor))
def __process_sensor(self, sensor: Sensor, value): sensor.value = round(value, 3) sensor.last_updated = calendar.timegm(datetime.now().timetuple()) self.__sensors_repository.set_sensor(sensor) dispatcher.send(SensorUpdateEvent.NAME, event=SensorUpdateEvent(sensor))