Пример #1
0
    def test_save(self):
        temperatures = {}

        def _get_temperature(sensor_id):
            return temperatures[sensor_id]

        controller = GatewayThermostatMappingTests._create_controller(
            get_sensor_temperature_status=_get_temperature)

        room = Room(number=5)
        room.save()

        thermostat_group = ThermostatGroup(number=0, name='global')
        thermostat_group.save()
        thermostat = Thermostat(
            number=10,
            start=0,  # 0 is on a thursday
            name='thermostat',
            thermostat_group=thermostat_group)
        thermostat.save()

        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        dto = heating_thermostats[0]  # type: ThermostatDTO

        default_schedule_dto = ThermostatScheduleDTO(temp_day_1=20.0,
                                                     start_day_1='07:00',
                                                     end_day_1='09:00',
                                                     temp_day_2=21.0,
                                                     start_day_2='17:00',
                                                     end_day_2='22:00',
                                                     temp_night=16.0)

        Sensor.create(number=15)

        dto.room = 5
        dto.sensor = 15
        dto.output0 = 5
        dto.name = 'changed'
        dto.auto_thu = ThermostatScheduleDTO(temp_night=10,
                                             temp_day_1=15,
                                             temp_day_2=30,
                                             start_day_1='08:00',
                                             end_day_1='10:30',
                                             start_day_2='16:00',
                                             end_day_2='18:45')

        temperatures[15] = 5.0
        controller.save_heating_thermostats([dto])

        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        dto = heating_thermostats[0]  # type: ThermostatDTO

        self.assertEqual(
            ThermostatDTO(id=10,
                          name='changed',
                          setp3=16.0,
                          setp4=15.0,
                          setp5=22.0,
                          sensor=15,
                          pid_p=120.0,
                          pid_i=0.0,
                          pid_d=0.0,
                          room=5,
                          output0=5,
                          permanent_manual=True,
                          auto_mon=default_schedule_dto,
                          auto_tue=default_schedule_dto,
                          auto_wed=default_schedule_dto,
                          auto_thu=ThermostatScheduleDTO(temp_night=10.0,
                                                         temp_day_1=15.0,
                                                         temp_day_2=30.0,
                                                         start_day_1='08:00',
                                                         end_day_1='10:30',
                                                         start_day_2='16:00',
                                                         end_day_2='18:45'),
                          auto_fri=default_schedule_dto,
                          auto_sat=default_schedule_dto,
                          auto_sun=default_schedule_dto), dto)
Пример #2
0
    def test_save(self):
        temperatures = {}

        def _get_temperature(sensor_id):
            return temperatures[sensor_id]

        controller = GatewayThermostatMappingTests._create_controller(
            get_sensor_temperature_status=_get_temperature)

        thermostat_group = ThermostatGroup(number=0, name='global')
        thermostat_group.save()
        thermostat = Thermostat(
            number=10,
            start=0,  # 0 is on a thursday
            name='thermostat',
            thermostat_group=thermostat_group)
        thermostat.save()

        for i in range(7):
            day_schedule = DaySchedule(index=i, content='{}', mode='heating')
            day_schedule.thermostat = thermostat
            day_schedule.save()

        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        dto = heating_thermostats[0]  # type: ThermostatDTO

        Sensor.create(number=15)

        dto.room = 5  # This field won't be saved
        dto.sensor = 15
        dto.output0 = 5
        dto.name = 'changed'
        dto.auto_thu = ThermostatScheduleDTO(temp_night=10,
                                             temp_day_1=15,
                                             temp_day_2=30,
                                             start_day_1='08:00',
                                             end_day_1='10:30',
                                             start_day_2='16:00',
                                             end_day_2='18:45')

        temperatures[15] = 5.0
        controller.save_heating_thermostats([
            (dto, ['sensor', 'output0', 'name', 'auto_thu'])
        ])

        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        dto = heating_thermostats[0]  # type: ThermostatDTO

        self.assertEqual(
            ThermostatDTO(
                id=10,
                name='changed',
                setp3=14.0,
                setp4=14.0,
                setp5=14.0,
                sensor=15,
                pid_p=120.0,
                pid_i=0.0,
                pid_d=0.0,
                room=None,  # Unchanged
                output0=5,
                permanent_manual=True,
                auto_thu=ThermostatScheduleDTO(temp_night=10.0,
                                               temp_day_1=15.0,
                                               temp_day_2=30.0,
                                               start_day_1='08:00',
                                               end_day_1='10:30',
                                               start_day_2='16:00',
                                               end_day_2='18:45')),
            dto)