Пример #1
0
    def test_orm_to_dto_mapping(self):
        controller = GatewayThermostatMappingTests._create_controller()

        group, _ = ThermostatGroup.get_or_create(
            number=0,
            name='Default',
            on=True,
            mode=ThermostatGroup.Modes.HEATING)
        thermostat = Thermostat(
            number=10,
            start=0,  # 0 is on a thursday
            name='thermostat',
            thermostat_group=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

        self.assertEqual(
            ThermostatDTO(id=10,
                          name='thermostat',
                          setp3=14.0,
                          setp4=14.0,
                          setp5=14.0,
                          sensor=None,
                          pid_p=120.0,
                          pid_i=0.0,
                          pid_d=0.0,
                          room=None,
                          permanent_manual=True), dto)

        day_schedule = thermostat.heating_schedules()[0]  # type: DaySchedule
        day_schedule.schedule_data = {
            0: 5.0,
            120: 5.5,  # 120 and 1200 are selected because 120 < 1200,
            1200: 6.0,  # but str(120) > str(1200)
            3600: 6.5,
            7500: 7.0
        }
        day_schedule.save()
        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        dto = heating_thermostats[0]  # type: ThermostatDTO

        self.assertEqual(
            ThermostatScheduleDTO(temp_night=5.0,
                                  temp_day_1=5.5,
                                  temp_day_2=6.5,
                                  start_day_1='00:02',
                                  end_day_1='00:20',
                                  start_day_2='01:00',
                                  end_day_2='02:05'), dto.auto_thu)
Пример #2
0
    def test_load(self):
        controller = GatewayThermostatMappingTests._create_controller()

        group, _ = ThermostatGroup.get_or_create(
            number=0,
            name='Default',
            on=True,
            mode=ThermostatGroup.Modes.HEATING)
        thermostat = Thermostat(number=10,
                                start=0,
                                name='thermostat',
                                thermostat_group=group)
        thermostat.save()

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

        # Validate load calls
        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        cooling_thermostats = controller.load_cooling_thermostats()
        self.assertEqual(1, len(cooling_thermostats))
        heating_thermostat_dto = heating_thermostats[0]
        cooling_thermostat_dto = cooling_thermostats[0]
        self.assertEqual(heating_thermostat_dto,
                         controller.load_heating_thermostat(10))
        self.assertEqual(cooling_thermostat_dto,
                         controller.load_cooling_thermostat(10))

        # Validate contents
        # Presets have a different default value for cooling vs heating
        heating_thermostat_dto.setp3 = cooling_thermostat_dto.setp3
        heating_thermostat_dto.setp4 = cooling_thermostat_dto.setp4
        heating_thermostat_dto.setp5 = cooling_thermostat_dto.setp5
        self.assertEqual(heating_thermostat_dto, cooling_thermostat_dto)
        self.assertEqual('thermostat', heating_thermostat_dto.name)
        self.assertEqual(thermostat.number, heating_thermostat_dto.id)
Пример #3
0
    def test_load(self):
        controller = GatewayThermostatMappingTests._create_controller()

        group, _ = ThermostatGroup.get_or_create(
            number=0,
            name='Default',
            on=True,
            mode=ThermostatGroup.Modes.HEATING)
        thermostat = Thermostat(number=10,
                                start=0,
                                name='thermostat',
                                thermostat_group=group)
        thermostat.save()

        # Validate load calls
        heating_thermostats = controller.load_heating_thermostats()
        self.assertEqual(1, len(heating_thermostats))
        cooling_thermostats = controller.load_cooling_thermostats()
        self.assertEqual(1, len(cooling_thermostats))
        heating_thermostat_dto = heating_thermostats[0]
        cooling_thermostat_dto = cooling_thermostats[0]
        self.assertEqual(heating_thermostat_dto,
                         controller.load_heating_thermostat(10))
        self.assertEqual(cooling_thermostat_dto,
                         controller.load_cooling_thermostat(10))

        # Validate contents
        # Presets & schedules have a different default value for cooling vs heating
        heating_thermostat_dto.setp3 = cooling_thermostat_dto.setp3
        heating_thermostat_dto.setp4 = cooling_thermostat_dto.setp4
        heating_thermostat_dto.setp5 = cooling_thermostat_dto.setp5
        for day in ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']:
            setattr(heating_thermostat_dto, 'auto_{0}'.format(day),
                    getattr(cooling_thermostat_dto, 'auto_{0}'.format(day)))
        self.assertEqual(heating_thermostat_dto, cooling_thermostat_dto)
        self.assertEqual('thermostat', heating_thermostat_dto.name)
        self.assertEqual(thermostat.number, heating_thermostat_dto.id)