示例#1
0
 def save_shutter_groups(self, shutter_groups):  # type: (List[Tuple[ShutterGroupDTO, List[str]]]) -> None
     shutter_groups_to_save = []
     for shutter_group_dto, fields in shutter_groups:
         shutter_group = ShutterGroup.get_or_none(number=shutter_group_dto.id)  # type: ShutterGroup
         if shutter_group is None:
             continue
         if 'room' in fields:
             if shutter_group_dto.room is None:
                 shutter_group.room = None
             elif 0 <= shutter_group_dto.room <= 100:
                 shutter_group.room, _ = Room.get_or_create(number=shutter_group_dto.room)
             shutter_group.save()
         shutter_groups_to_save.append((shutter_group_dto, fields))
     self._master_controller.save_shutter_groups(shutter_groups_to_save)
示例#2
0
 def save_outputs(self, outputs):  # type: (List[OutputDTO]) -> None
     outputs_to_save = []
     for output_dto in outputs:
         output = Output.get_or_none(number=output_dto.id)  # type: Output
         if output is None:
             logger.info('Ignored saving non-existing Output {0}'.format(
                 output_dto.id))
         if 'room' in output_dto.loaded_fields:
             if output_dto.room is None:
                 output.room = None
             elif 0 <= output_dto.room <= 100:
                 output.room, _ = Room.get_or_create(number=output_dto.room)
             output.save()
         outputs_to_save.append(output_dto)
     self._master_controller.save_outputs(outputs_to_save)
示例#3
0
 def save_shutters(self, shutters):  # type: (List[Tuple[ShutterDTO, List[str]]]) -> None
     shutters_to_save = []
     for shutter_dto, fields in shutters:
         shutter = Shutter.get_or_none(number=shutter_dto.id)  # type: Shutter
         if shutter is None:
             logger.info('Ignored saving non-existing Shutter {0}'.format(shutter_dto.id))
         if 'room' in fields:
             if shutter_dto.room is None:
                 shutter.room = None
             elif 0 <= shutter_dto.room <= 100:
                 shutter.room, _ = Room.get_or_create(number=shutter_dto.room)
             shutter.save()
         shutters_to_save.append((shutter_dto, fields))
     self._master_controller.save_shutters(shutters_to_save)
     self.update_config(self.load_shutters())
示例#4
0
 def save_sensors(
         self,
         sensors):  # type: (List[Tuple[SensorDTO, List[str]]]) -> None
     sensors_to_save = []
     for sensor_dto, fields in sensors:
         sensor_ = Sensor.get_or_none(number=sensor_dto.id)  # type: Sensor
         if sensor_ is None:
             logger.info('Ignored saving non-existing Sensor {0}'.format(
                 sensor_dto.id))
         if 'room' in fields:
             if sensor_dto.room is None:
                 sensor_.room = None
             elif 0 <= sensor_dto.room <= 100:
                 sensor_.room, _ = Room.get_or_create(
                     number=sensor_dto.room)
             sensor_.save()
         sensors_to_save.append((sensor_dto, fields))
     self._master_controller.save_sensors(sensors_to_save)
示例#5
0
 def save_inputs(self, inputs):  # type: (List[InputDTO]) -> None
     inputs_to_save = []
     for input_dto in inputs:
         input_ = Input.get_or_none(number=input_dto.id)  # type: Input
         if input_ is None:
             logger.info('Ignored saving non-existing Input {0}'.format(
                 input_dto.id))
         if 'event_enabled' in input_dto.loaded_fields:
             input_.event_enabled = input_dto.event_enabled
             input_.save()
         if 'room' in input_dto.loaded_fields:
             if input_dto.room is None:
                 input_.room = None
             elif 0 <= input_dto.room <= 100:
                 # TODO: Validation should happen on API layer
                 input_.room, _ = Room.get_or_create(number=input_dto.room)
             input_.save()
         inputs_to_save.append(input_dto)
     self._master_controller.save_inputs(inputs_to_save)
 def save_pulse_counters(self, pulse_counters):  # type: (List[PulseCounterDTO]) -> None
     pulse_counters_to_save = []
     for pulse_counter_dto in pulse_counters:
         pulse_counter = PulseCounter.get_or_none(number=pulse_counter_dto.id)  # type: PulseCounter
         if pulse_counter is None:
             raise DoesNotExist('A PulseCounter with id {0} could not be found'.format(pulse_counter_dto.id))
         if pulse_counter.source == 'master':
             # Only master pulse counters will be passed to the MasterController batch save
             pulse_counters_to_save.append(pulse_counter_dto)
             if 'name' in pulse_counter_dto.loaded_fields:
                 pulse_counter.name = pulse_counter_dto.name
         elif pulse_counter.source == 'gateway':
             pulse_counter = PulseCounterMapper.dto_to_orm(pulse_counter_dto)
         else:
             logger.warning('Trying to save a PulseCounter with unknown source {0}'.format(pulse_counter.source))
             continue
         if 'room' in pulse_counter_dto.loaded_fields:
             if pulse_counter_dto.room is None:
                 pulse_counter.room = None
             elif 0 <= pulse_counter_dto.room <= 100:
                 pulse_counter.room, _ = Room.get_or_create(number=pulse_counter_dto.room)
         pulse_counter.save()
     self._master_controller.save_pulse_counters(pulse_counters_to_save)