Beispiel #1
0
 def serialize(shutter_dto,
               fields):  # type: (ShutterDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         shutter_dto.id,
         'name':
         shutter_dto.name,
         'timer_up':
         Toolbox.denonify(shutter_dto.timer_up, ShutterSerializer.BYTE_MAX),
         'timer_down':
         Toolbox.denonify(shutter_dto.timer_down,
                          ShutterSerializer.BYTE_MAX),
         'up_down_config':
         Toolbox.denonify(shutter_dto.up_down_config,
                          ShutterSerializer.BYTE_MAX),
         'group_1':
         Toolbox.denonify(shutter_dto.group_1, ShutterSerializer.BYTE_MAX),
         'group_2':
         Toolbox.denonify(shutter_dto.group_2, ShutterSerializer.BYTE_MAX),
         'room':
         Toolbox.denonify(shutter_dto.room, ShutterSerializer.BYTE_MAX),
         'steps':
         Toolbox.denonify(shutter_dto.steps, ShutterSerializer.WORD_MAX)
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #2
0
 def serialize(
         thermostat_dto,
         fields):  # type: (ThermostatDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         thermostat_dto.id,
         'name':
         thermostat_dto.name,
         'room':
         Toolbox.denonify(thermostat_dto.room,
                          ThermostatSerializer.BYTE_MAX),
         'setp0':
         thermostat_dto.setp0,
         'setp1':
         thermostat_dto.setp1,
         'setp2':
         thermostat_dto.setp2,
         'setp3':
         thermostat_dto.setp3,
         'setp4':
         thermostat_dto.setp4,
         'setp5':
         thermostat_dto.setp5,
         'sensor':
         Toolbox.denonify(thermostat_dto.sensor,
                          ThermostatSerializer.BYTE_MAX),
         'output0':
         Toolbox.denonify(thermostat_dto.output0,
                          ThermostatSerializer.BYTE_MAX),
         'output1':
         Toolbox.denonify(thermostat_dto.output1,
                          ThermostatSerializer.BYTE_MAX),
         'pid_p':
         Toolbox.denonify(thermostat_dto.pid_p,
                          ThermostatSerializer.BYTE_MAX),
         'pid_i':
         Toolbox.denonify(thermostat_dto.pid_i,
                          ThermostatSerializer.BYTE_MAX),
         'pid_d':
         Toolbox.denonify(thermostat_dto.pid_d,
                          ThermostatSerializer.BYTE_MAX),
         'pid_int':
         Toolbox.denonify(thermostat_dto.pid_int,
                          ThermostatSerializer.BYTE_MAX),
         'permanent_manual':
         thermostat_dto.permanent_manual
     }
     for day in ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']:
         field = 'auto_{0}'.format(day)
         dto_data = getattr(thermostat_dto,
                            field)  # type: ThermostatScheduleDTO
         if dto_data is None:
             raise RuntimeError(
                 'Schedules are mandatory in the ThermostatSerializer')
         data[field] = [
             dto_data.temp_night, dto_data.start_day_1, dto_data.end_day_1,
             dto_data.temp_day_1, dto_data.start_day_2, dto_data.end_day_2,
             dto_data.temp_day_2
         ]
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #3
0
 def serialize(
         thermostat_group_dto,
         fields):  # type: (ThermostatGroupDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         thermostat_group_dto.id,
         'outside_sensor':
         Toolbox.denonify(thermostat_group_dto.outside_sensor_id,
                          ThermostatGroupSerializer.BYTE_MAX),
         'threshold_temp':
         Toolbox.denonify(thermostat_group_dto.threshold_temperature,
                          ThermostatGroupSerializer.BYTE_MAX),
         'pump_delay':
         Toolbox.denonify(thermostat_group_dto.pump_delay,
                          ThermostatGroupSerializer.BYTE_MAX)
     }
     for mode in ['heating', 'cooling']:
         for i in range(4):
             output = 'switch_to_{0}_output_{1}'.format(mode, i)
             value = 'switch_to_{0}_value_{1}'.format(mode, i)
             field = 'switch_to_{0}_{1}'.format(mode, i)
             dto_value = getattr(thermostat_group_dto,
                                 field)  # type: Optional[Tuple[int, int]]
             data[output] = Toolbox.denonify(
                 None if dto_value is None else dto_value[0],
                 ThermostatGroupSerializer.BYTE_MAX)
             data[value] = Toolbox.denonify(
                 None if dto_value is None else dto_value[1],
                 ThermostatGroupSerializer.BYTE_MAX)
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #4
0
 def serialize(ventilation_dto, fields):
     # type: (VentilationDTO, Optional[List[str]]) -> Dict[str,Any]
     data = {
         'id':
         ventilation_dto.id,
         'external_id':
         Toolbox.denonify(ventilation_dto.external_id, ''),
         'source': {
             'type': ventilation_dto.source.type,
             'name': ventilation_dto.source.name
         },
         'name':
         Toolbox.denonify(ventilation_dto.name, ''),
         'amount_of_levels':
         Toolbox.denonify(ventilation_dto.amount_of_levels, 0),
         'device': {
             'vendor': Toolbox.denonify(ventilation_dto.device_vendor, ''),
             'type': Toolbox.denonify(ventilation_dto.device_type, '')
         }
     }
     if ventilation_dto.device_serial:
         data['device'].update({
             'serial':
             Toolbox.denonify(ventilation_dto.device_serial, '')
         })
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #5
0
 def serialize(
         global_feedback_dto,
         fields):  # type: (GlobalFeedbackDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         global_feedback_dto.id,
         'can_led_1_id':
         Toolbox.denonify(global_feedback_dto.can_led_1.id,
                          GlobalFeedbackSerializer.BYTE_MAX),
         'can_led_1_function':
         global_feedback_dto.can_led_1.function,
         'can_led_2_id':
         Toolbox.denonify(global_feedback_dto.can_led_2.id,
                          GlobalFeedbackSerializer.BYTE_MAX),
         'can_led_2_function':
         global_feedback_dto.can_led_2.function,
         'can_led_3_id':
         Toolbox.denonify(global_feedback_dto.can_led_3.id,
                          GlobalFeedbackSerializer.BYTE_MAX),
         'can_led_3_function':
         global_feedback_dto.can_led_3.function,
         'can_led_4_id':
         Toolbox.denonify(global_feedback_dto.can_led_4.id,
                          GlobalFeedbackSerializer.BYTE_MAX),
         'can_led_4_function':
         global_feedback_dto.can_led_4.function
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #6
0
 def serialize(room_dto,
               fields):  # type: (RoomDTO, Optional[List[str]]) -> Dict
     data = {
         'id': room_dto.id,
         'name': Toolbox.denonify(room_dto.name, ''),
         'floor': 255 if room_dto.floor is None else room_dto.floor.id
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #7
0
 def serialize(output_state_dto, fields):
     # type: (OutputStateDTO, Optional[List[str]]) -> Dict
     data = {
         'id': output_state_dto.id,
         'status': 1 if output_state_dto.status else 0,
         'ctimer': output_state_dto.ctimer,
         'dimmer': output_state_dto.dimmer,
         'locked': output_state_dto.locked
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #8
0
 def serialize(status_dto, fields):
     # type: (VentilationStatusDTO, Optional[List[str]]) -> Dict[str,Any]
     data = {
         'id': status_dto.id,
         'mode': status_dto.mode,
         'level': status_dto.level,
         # timer value is write only
         'remaining_time': status_dto.remaining_time
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #9
0
 def serialize(sensor_dto,
               fields):  # type: (SensorDTO, Optional[List[str]]) -> Dict
     data = {
         'id': sensor_dto.id,
         'name': sensor_dto.name,
         'offset': Toolbox.denonify(sensor_dto.offset, 0),
         'room': Toolbox.denonify(sensor_dto.room,
                                  SensorSerializer.BYTE_MAX),
         'virtual': sensor_dto.virtual
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #10
0
 def serialize(status_dto, fields):
     # type: (VentilationStatusDTO, Optional[List[str]]) -> Dict[str,Any]
     data = {
         'id': status_dto.id,
         'mode': status_dto.mode,
         'level': status_dto.level,
         'remaining_time': status_dto.remaining_time,
         'timer': status_dto.timer,
         'connected': status_dto.is_connected
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #11
0
 def serialize(rtd10_dto,
               fields):  # type: (RTD10DTO, Optional[List[str]]) -> Dict
     data = {'id': rtd10_dto.id}
     for field in [
             'temp_setpoint_output', 'ventilation_speed_output',
             'ventilation_speed_value', 'mode_output', 'mode_value',
             'on_off_output', 'poke_angle_output', 'poke_angle_value',
             'room'
     ]:
         data[field] = Toolbox.denonify(getattr(rtd10_dto, field),
                                        RTD10Serializer.BYTE_MAX)
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #12
0
 def serialize(
         group_action_dto,
         fields):  # type: (GroupActionDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         group_action_dto.id,
         'name':
         group_action_dto.name,
         'actions':
         ','.join([str(action) for action in group_action_dto.actions])
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #13
0
 def serialize(module_dto,
               fields):  # type: (ModuleDTO, Optional[List[str]]) -> Dict
     data = {'address': module_dto.address}  # type: Dict[str, Any]
     if module_dto.source == ModuleDTO.Source.MASTER:
         category_map = {
             ModuleDTO.ModuleType.CAN_CONTROL: 'INPUT',
             ModuleDTO.ModuleType.SENSOR: 'INPUT',
             ModuleDTO.ModuleType.INPUT: 'INPUT',
             ModuleDTO.ModuleType.SHUTTER: 'SHUTTER',
             ModuleDTO.ModuleType.OUTPUT: 'OUTPUT',
             ModuleDTO.ModuleType.DIM_CONTROL: 'OUTPUT',
             ModuleDTO.ModuleType.OPEN_COLLECTOR: 'OUTPUT',
             None: 'UNKNOWN'
         }
         type_int = int(module_dto.address.split('.')[0])
         data.update({
             'type':
             chr(type_int) if 32 <= type_int <= 126 else None,
             'hardware_type':
             module_dto.hardware_type,
             'module_nr':
             module_dto.order,
             'is_can':
             (module_dto.hardware_type == ModuleDTO.HardwareType.EMULATED or
              module_dto.module_type == ModuleDTO.ModuleType.CAN_CONTROL),
             'is_virtual':
             module_dto.hardware_type == ModuleDTO.HardwareType.VIRTUAL,
             'category':
             category_map.get(module_dto.module_type, 'UNKNOWN')
         })
         if module_dto.hardware_type == ModuleDTO.HardwareType.PHYSICAL:
             data.update({
                 'firmware': module_dto.firmware_version,
                 'hardware': module_dto.hardware_version
             })
     else:
         module_type_map = {
             ModuleDTO.ModuleType.ENERGY: 'E',
             ModuleDTO.ModuleType.POWER: 'P',
             ModuleDTO.ModuleType.P1_CONCENTRATOR: 'C',
             None: 'U'
         }
         data.update({
             'type':
             module_type_map.get(module_dto.module_type, 'U'),
             'firmware':
             module_dto.firmware_version,
             'address':
             module_dto.address,
             'id':
             module_dto.order
         })
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #14
0
 def serialize(
     global_rtd10_dto, fields
 ):  # type: (GlobalRTD10DTO, Optional[List[str]]) -> Dict[str, Any]
     data = {}
     for temperature in GlobalRTD10DTO.TEMPERATURES:
         formatted_temp = GlobalRTD10Serializer._temp_to_str(temperature)
         data['output_value_heating_{0}'.format(
             formatted_temp)] = global_rtd10_dto.heating_values.get(
                 temperature, GlobalRTD10Serializer.BYTE_MAX)
         data['output_value_cooling_{0}'.format(
             formatted_temp)] = global_rtd10_dto.cooling_values.get(
                 temperature, GlobalRTD10Serializer.BYTE_MAX)
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #15
0
 def serialize(schedule_dto,
               fields):  # type: (ScheduleDTO, Optional[List[str]]) -> Dict
     data = {
         'id': schedule_dto.id,
         'name': schedule_dto.name,
         'start': schedule_dto.start,
         'repeat': schedule_dto.repeat,
         'duration': schedule_dto.duration,
         'end': schedule_dto.end,
         'schedule_type': schedule_dto.action,
         'arguments': schedule_dto.arguments,
         'status': schedule_dto.status,
         'last_executed': schedule_dto.last_executed,
         'next_execution': schedule_dto.next_execution
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #16
0
 def serialize(
         shutter_group_dto,
         fields):  # type: (ShutterGroupDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         shutter_group_dto.id,
         'timer_up':
         Toolbox.denonify(shutter_group_dto.timer_up,
                          ShutterGroupSerializer.BYTE_MAX),
         'timer_down':
         Toolbox.denonify(shutter_group_dto.timer_down,
                          ShutterGroupSerializer.BYTE_MAX),
         'room':
         Toolbox.denonify(shutter_group_dto.room,
                          ShutterGroupSerializer.BYTE_MAX)
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #17
0
 def serialize(pump_group_dto,
               fields):  # type: (PumpGroupDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         pump_group_dto.id,
         'output':
         Toolbox.denonify(pump_group_dto.pump_output_id,
                          PumpGroupSerializer.BYTE_MAX),
         'outputs':
         ','.join(
             str(output_id)
             for output_id in pump_group_dto.valve_output_ids),
         'room':
         Toolbox.denonify(pump_group_dto.room_id,
                          PumpGroupSerializer.BYTE_MAX)
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #18
0
 def serialize(
         pulse_counter_dto,
         fields):  # type: (PulseCounterDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         pulse_counter_dto.id,
         'name':
         pulse_counter_dto.name,
         'input':
         Toolbox.denonify(pulse_counter_dto.input_id,
                          PulseCounterSerializer.BYTE_MAX),
         'persistent':
         pulse_counter_dto.persistent,
         'room':
         Toolbox.denonify(pulse_counter_dto.room,
                          PulseCounterSerializer.BYTE_MAX)
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #19
0
 def serialize(output_dto,
               fields):  # type: (OutputDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         output_dto.id,
         'module_type':
         output_dto.module_type,
         'name':
         output_dto.name,
         'timer':
         Toolbox.denonify(output_dto.timer, OutputSerializer.WORD_MAX),
         'floor':
         Toolbox.denonify(output_dto.floor, OutputSerializer.BYTE_MAX),
         'type':
         Toolbox.denonify(output_dto.output_type,
                          OutputSerializer.BYTE_MAX),
         'lock_bit_id':
         Toolbox.denonify(output_dto.lock_bit_id,
                          OutputSerializer.BYTE_MAX),
         'can_led_1_id':
         Toolbox.denonify(output_dto.can_led_1.id,
                          OutputSerializer.BYTE_MAX),
         'can_led_1_function':
         output_dto.can_led_1.function,
         'can_led_2_id':
         Toolbox.denonify(output_dto.can_led_2.id,
                          OutputSerializer.BYTE_MAX),
         'can_led_2_function':
         output_dto.can_led_2.function,
         'can_led_3_id':
         Toolbox.denonify(output_dto.can_led_3.id,
                          OutputSerializer.BYTE_MAX),
         'can_led_3_function':
         output_dto.can_led_3.function,
         'can_led_4_id':
         Toolbox.denonify(output_dto.can_led_4.id,
                          OutputSerializer.BYTE_MAX),
         'can_led_4_function':
         output_dto.can_led_4.function,
         'room':
         Toolbox.denonify(output_dto.room, OutputSerializer.BYTE_MAX)
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #20
0
 def serialize(input_dto,
               fields):  # type: (InputDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         input_dto.id,
         'module_type':
         input_dto.module_type,
         'name':
         input_dto.name,
         'action':
         Toolbox.denonify(input_dto.action, InputSerializer.BYTE_MAX),
         'basic_actions':
         ','.join([str(action) for action in input_dto.basic_actions]),
         'invert':
         0 if input_dto.invert else 255,
         'room':
         Toolbox.denonify(input_dto.room, InputSerializer.BYTE_MAX),
         'can':
         'C' if input_dto.can else ' ',
         'event_enabled':
         input_dto.event_enabled
     }
     return SerializerToolbox.filter_fields(data, fields)
Beispiel #21
0
 def serialize(
         thermostat_dto,
         fields):  # type: (ThermostatDTO, Optional[List[str]]) -> Dict
     data = {
         'id':
         thermostat_dto.id,
         'name':
         thermostat_dto.name,
         'room':
         Toolbox.denonify(thermostat_dto.room,
                          ThermostatSerializer.BYTE_MAX),
         'setp0':
         thermostat_dto.setp0,
         'setp1':
         thermostat_dto.setp1,
         'setp2':
         thermostat_dto.setp2,
         'setp3':
         thermostat_dto.setp3,
         'setp4':
         thermostat_dto.setp4,
         'setp5':
         thermostat_dto.setp5,
         'sensor':
         Toolbox.denonify(thermostat_dto.sensor,
                          ThermostatSerializer.BYTE_MAX),
         'output0':
         Toolbox.denonify(thermostat_dto.output0,
                          ThermostatSerializer.BYTE_MAX),
         'output1':
         Toolbox.denonify(thermostat_dto.output1,
                          ThermostatSerializer.BYTE_MAX),
         'pid_p':
         Toolbox.denonify(thermostat_dto.pid_p,
                          ThermostatSerializer.BYTE_MAX),
         'pid_i':
         Toolbox.denonify(thermostat_dto.pid_i,
                          ThermostatSerializer.BYTE_MAX),
         'pid_d':
         Toolbox.denonify(thermostat_dto.pid_d,
                          ThermostatSerializer.BYTE_MAX),
         'pid_int':
         Toolbox.denonify(thermostat_dto.pid_int,
                          ThermostatSerializer.BYTE_MAX),
         'permanent_manual':
         thermostat_dto.permanent_manual
     }
     for day in ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']:
         field = 'auto_{0}'.format(day)
         dto_data = getattr(thermostat_dto,
                            field)  # type: ThermostatScheduleDTO
         if dto_data is None:
             # TODO: Remove once UI can handle "no schedule"
             dto_data = ThermostatScheduleDTO(temp_night=16,
                                              temp_day_1=20,
                                              temp_day_2=20,
                                              start_day_1="07:00",
                                              end_day_1="09:00",
                                              start_day_2="16:00",
                                              end_day_2="22:00")
         data[field] = [
             dto_data.temp_night, dto_data.start_day_1, dto_data.end_day_1,
             dto_data.temp_day_1, dto_data.start_day_2, dto_data.end_day_2,
             dto_data.temp_day_2
         ]
     return SerializerToolbox.filter_fields(data, fields)