Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def dto_to_orm(
         thermostat_group_dto,
         fields):  # type: (ThermostatGroupDTO, List[str]) -> EepromModel
     data = {}  # type: Dict[str, Any]
     for dto_field, orm_field in {
             'outside_sensor_id': 'outside_sensor',
             'threshold_temperature': 'threshold_temp',
             'pump_delay': 'pump_delay'
     }.items():
         if dto_field in fields:
             data[orm_field] = Toolbox.denonify(
                 getattr(thermostat_group_dto, dto_field),
                 ThermostatGroupMapper.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)
             if field in fields:
                 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],
                     ThermostatGroupMapper.BYTE_MAX)
                 data[value] = Toolbox.denonify(
                     None if dto_value is None else dto_value[1],
                     ThermostatGroupMapper.BYTE_MAX)
     return GlobalThermostatConfiguration.deserialize(data)
Exemplo n.º 4
0
 def dto_to_orm(model_type, pump_group_dto):  # type: (Type[EepromModel], PumpGroupDTO) -> EepromModel
     data = {'id': pump_group_dto.id}  # type: Dict[str, Any]
     if 'pump_output_id' in pump_group_dto.loaded_fields:
         data['output'] = Toolbox.denonify(pump_group_dto.pump_output_id, PumpGroupMapper.BYTE_MAX)
     if 'valve_output_ids' in pump_group_dto.loaded_fields:
         data['outputs'] = ','.join(str(output_id) for output_id in pump_group_dto.valve_output_ids)
     if 'room_id' in pump_group_dto.loaded_fields:
         data['room'] = Toolbox.denonify(pump_group_dto.room_id, PumpGroupMapper.BYTE_MAX)
     return model_type.deserialize(data)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def dto_to_orm(shutter_dto):  # type: (ShutterDTO) -> EepromModel
     data = {'id': shutter_dto.id,
             'name': shutter_dto.name}
     for field in ['name']:
         if field in shutter_dto.loaded_fields:
             data[field] = getattr(shutter_dto, field)
     for field in ['timer_up', 'timer_down', 'up_down_config', 'group_1', 'group_2']:
         if field in shutter_dto.loaded_fields:
             data[field] = Toolbox.denonify(getattr(shutter_dto, field), ShutterMapper.BYTE_MAX)
     for field in ['steps']:
         if field in shutter_dto.loaded_fields:
             data[field] = Toolbox.denonify(getattr(shutter_dto, field), ShutterMapper.WORD_MAX)
     return ShutterConfiguration.deserialize(data)
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def dto_to_orm(
     model_type, thermostat_dto, fields
 ):  # type: (Type[EepromModel], ThermostatDTO, List[str]) -> EepromModel
     data = {'id': thermostat_dto.id}  # type: Dict[str, Any]
     for field in ['name', 'permanent_manual'
                   ] + ['setp{0}'.format(i) for i in range(6)]:
         if field in fields:
             data[field] = getattr(thermostat_dto, field)
     for field in [
             'sensor', 'output0', 'output1', 'pid_p', 'pid_i', 'pid_d',
             'pid_int', 'room'
     ]:
         if field in fields:
             data[field] = Toolbox.denonify(getattr(thermostat_dto, field),
                                            ThermostatMapper.BYTE_MAX)
     for day in ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']:
         field = 'auto_{0}'.format(day)
         if field not in fields:
             continue
         dto_data = getattr(thermostat_dto,
                            field)  # type: ThermostatScheduleDTO
         if dto_data is None:
             continue
         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 model_type.deserialize(data)
Exemplo n.º 9
0
 def dto_to_orm(output_dto):  # type: (OutputDTO) -> EepromModel
     data = {'id': output_dto.id}
     for dto_field, data_field in {
             'module_type': 'module_type',
             'name': 'name',
             'output_type': 'type'
     }.items():
         if dto_field in output_dto.loaded_fields:
             data[data_field] = getattr(output_dto, dto_field)
     for dto_field, (data_field, default) in {
             'timer': ('timer', OutputMapper.WORD_MAX),
             'floor': ('floor', OutputMapper.BYTE_MAX),
             'lock_bit_id': ('lock_bit_id', OutputMapper.BYTE_MAX)
     }.items():
         if dto_field in output_dto.loaded_fields:
             data[data_field] = Toolbox.denonify(
                 getattr(output_dto, dto_field), default)
     for i in range(4):
         base_field = 'can_led_{0}'.format(i + 1)
         if base_field in output_dto.loaded_fields:
             id_field = '{0}_id'.format(base_field)
             function_field = '{0}_function'.format(base_field)
             data[id_field] = getattr(output_dto, base_field).id
             data[function_field] = getattr(output_dto, base_field).function
     return OutputConfiguration.deserialize(data)
Exemplo n.º 10
0
 def dto_to_orm(shutter_dto):  # type: (ShutterGroupDTO) -> EepromModel
     data = {'id': shutter_dto.id}
     for field in ['timer_up', 'timer_down']:
         if field in shutter_dto.loaded_fields:
             data[field] = Toolbox.denonify(getattr(shutter_dto, field),
                                            ShutterGroupMapper.BYTE_MAX)
     return ShutterGroupConfiguration.deserialize(data)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
0
    def set_thermostat_mode(self,
                            thermostat_on,
                            cooling_mode=False,
                            cooling_on=False,
                            automatic=None,
                            setpoint=None):
        # type: (bool, bool, bool, Optional[bool], Optional[int]) -> None
        """ Set the mode of the thermostats. """
        _ = thermostat_on  # Still accept `thermostat_on` for backwards compatibility

        # Figure out whether the system should be on or off
        set_on = False
        if cooling_mode is True and cooling_on is True:
            set_on = True
        if cooling_mode is False:
            # Heating means threshold based
            thermostat_group = self.load_thermostat_group()
            outside_sensor = Toolbox.denonify(
                thermostat_group.outside_sensor_id, 255)
            current_temperatures = self._master_controller.get_sensors_temperature(
            )[:32]
            if len(current_temperatures) < 32:
                current_temperatures += [None
                                         ] * (32 - len(current_temperatures))
            if len(current_temperatures) > outside_sensor:
                current_temperature = current_temperatures[outside_sensor]
                set_on = thermostat_group.threshold_temperature > current_temperature
            else:
                set_on = True

        # Calculate and set the global mode
        mode = 0
        mode |= (1 if set_on is True else 0) << 7
        mode |= 1 << 6  # multi-tenant mode
        mode |= (1 if cooling_mode else 0) << 4
        if automatic is not None:
            mode |= (1 if automatic else 0) << 3
        self._master_controller.set_thermostat_mode(mode)

        # Caclulate and set the cooling/heating mode
        cooling_heating_mode = 0
        if cooling_mode is True:
            cooling_heating_mode = 1 if cooling_on is False else 2
        self._master_controller.set_thermostat_cooling_heating(
            cooling_heating_mode)

        # Then, set manual/auto
        if automatic is not None:
            action_number = 1 if automatic is True else 0
            self._master_controller.set_thermostat_automatic(action_number)

        # If manual, set the setpoint if appropriate
        if automatic is False and setpoint is not None and 3 <= setpoint <= 5:
            self._master_controller.set_thermostat_all_setpoints(setpoint)

        self.invalidate_cache(THERMOSTATS)
        self.increase_interval(THERMOSTATS, interval=2, window=10)
Exemplo n.º 16
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)
Exemplo n.º 17
0
 def dto_to_orm(
         pulse_counter_dto):  # type: (PulseCounterDTO) -> EepromModel
     data = {'id': pulse_counter_dto.id}  # type: Dict[str, Any]
     if 'name' in pulse_counter_dto.loaded_fields:
         data['name'] = Toolbox.shorten_name(pulse_counter_dto.name)
     if 'input_id' in pulse_counter_dto.loaded_fields:
         data['input'] = Toolbox.denonify(pulse_counter_dto.input_id,
                                          PulseCounterMapper.BYTE_MAX)
     return PulseCounterConfiguration.deserialize(data)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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)
Exemplo n.º 21
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)
Exemplo n.º 22
0
 def dto_to_orm(
     model_type, rtd10_dto, fields
 ):  # type: (Type[EepromModel], RTD10DTO, List[str]) -> EepromModel
     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'
     ]:
         if field in fields:
             data[field] = Toolbox.denonify(getattr(rtd10_dto, field),
                                            RTD10Mapper.BYTE_MAX)
     return model_type.deserialize(data)
Exemplo n.º 23
0
 def _publish_output_change(self, output_dto):
     # type: (OutputDTO) -> None
     event_status = {
         'on': output_dto.state.status,
         'locked': output_dto.state.locked
     }
     if output_dto.module_type in ['d', 'D']:
         event_status['value'] = output_dto.state.dimmer
     event_data = {
         'id': output_dto.id,
         'status': event_status,
         'location': {
             'room_id': Toolbox.denonify(output_dto.room, 255)
         }
     }
     gateway_event = GatewayEvent(GatewayEvent.Types.OUTPUT_CHANGE,
                                  event_data)
     self._pubsub.publish_gateway_event(PubSub.GatewayTopics.STATE,
                                        gateway_event)
Exemplo n.º 24
0
 def _thermostat_changed(self, thermostat_id, status):
     # type: (int, Dict[str,Any]) -> None
     """ Executed by the Thermostat Status tracker when an output changed state """
     location = {
         'room_id':
         Toolbox.denonify(self._thermostats_config[thermostat_id].room, 255)
     }
     gateway_event = GatewayEvent(
         GatewayEvent.Types.THERMOSTAT_CHANGE, {
             'id': thermostat_id,
             'status': {
                 'preset': status['preset'],
                 'current_setpoint': status['current_setpoint'],
                 'actual_temperature': status['actual_temperature'],
                 'output_0': status['output_0'],
                 'output_1': status['output_1']
             },
             'location': location
         })
     self._pubsub.publish_gateway_event(PubSub.GatewayTopics.STATE,
                                        gateway_event)
Exemplo n.º 25
0
 def dto_to_orm(input_dto):  # type: (InputDTO) -> EepromModel
     data = {'id': input_dto.id}  # type: Dict[str, Any]
     for dto_field, data_field in {
             'module_type': 'module_type',
             'name': 'name'
     }.items():
         if dto_field in input_dto.loaded_fields:
             data[data_field] = getattr(input_dto, dto_field)
     for dto_field, (data_field, default) in {
             'action': ('action', InputMapper.BYTE_MAX)
     }.items():
         if dto_field in input_dto.loaded_fields:
             data[data_field] = Toolbox.denonify(
                 getattr(input_dto, dto_field), default)
     if 'basic_actions' in input_dto.loaded_fields:
         data['basic_actions'] = ','.join(
             [str(action) for action in input_dto.basic_actions])
     if 'invert' in input_dto.loaded_fields:
         data['invert'] = 0 if input_dto.invert else 255
     if 'can' in input_dto.loaded_fields:
         data['can'] = 'C' if input_dto.can else ' '
     return InputConfiguration.deserialize(data)
Exemplo n.º 26
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)