def test_proximity_multiple_zones_no_zone_in_config(self):
        # setup a thermostat as component will fail without it
        self.hass.states.set(
            'thermostat.test1', '25.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })

        # setup proximity zone as these will be needed
        self.hass.states.set(
            'proximity.test1', '60',
            {
                'dir_of_travel': 'unknown',
                'friendly_name': 'test1',
                'nearest': 'Nick',
                'unit_of_measurement': 'km'
            })

        # setup proximity zone as these will be needed
        self.hass.states.set(
            'proximity.test2', '60',
            {
                'dir_of_travel': 'unknown',
                'friendly_name': 'test2',
                'nearest': 'Nick',
                'unit_of_measurement': 'km'
            })

        # no proximity zone in config entry
        assert not thermostat_control.setup(self.hass, {
            'thermostat_control': {
                'test1': {
                    'schedule': {
                        '07:00': 21.5,
                        '10:15': 24.5,
                        '15:45': 23.5,
                        '16:45': 20.5
                    },
                    'max_temp': 26,
                    'min_temp': 15,
                    'proximity': {
                        'distance_offset': 0.1,
                        'away_distance': 50
                    }
                }
            }
        })
    def test_no_schedule_in_config(self):
        # setup a thermostat as component will fail without it
        self.hass.states.set(
            'thermostat.test1', '25.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })

        # no schedule specified in config entry
        assert not thermostat_control.setup(self.hass, {
            'thermostat_control': {
                'test1': {
                    'max_temp': 26,
                    'min_temp': 15,
                    'proximity': {
                        'distance_offset': 0.1,
                        'away_distance': 50,
                        'zone': 'home'
                    }
                }
            }
        })
    def test_multiple_thermostats_no_thermostat_in_config(self):
        # setup a thermostat as this will be needed
        self.hass.states.set(
            'thermostat.test1', '23.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })
        self.hass.states.set(
            'thermostat.test2', '25.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })

        # no thermostat specified in config entry
        assert not thermostat_control.setup(self.hass, {
            'thermostat_control': {
                'test1': {
                    'schedule': {
                        '07:00': 21.5,
                        '10:15': 24.5,
                        '15:45': 23.5,
                        '16:45': 20.5
                    },
                    'max_temp': 26,
                    'min_temp': 15,
                    'proximity': {
                        'distance_offset': 0.1,
                        'away_distance': 50,
                        'zone': 'home'
                    }
                }
            }
        })
    def test_thermostat_exists(self):
        # setup a thermostat as component will fail without it
        self.hass.states.set(
            'thermostat.test1', '25.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })

        # thermostat does not exist
        assert not thermostat_control.setup(self.hass, {
            'thermostat_control': {
                'test1': {
                    'schedule': {
                        '07:00': 21.5,
                        '10:15': 24.5,
                        '15:45': 23.5,
                        '16:45': 20.5
                    },
                    'max_temp': 26,
                    'min_temp': 15,
                    'thermostat': 'does_not_exist',
                    'proximity': {
                        'distance_offset': 0.1,
                        'away_distance': 50,
                        'zone': 'home'
                    }
                }
            }
        })
 def test_no_thermostat(self):
     # mimic properly formatted config.yaml entry
     assert not thermostat_control.setup(self.hass, {
         'thermostat_control': {
             'test1': {
                 'schedule': {
                     '07:00': 21.5,
                     '10:15': 24.5,
                     '15:45': 23.5,
                     '16:45': 20.5
                 },
                 'max_temp': 26,
                 'min_temp': 15,
                 'proximity': {
                     'distance_offset': 0.1,
                     'away_distance': 50,
                     'zone': 'home'
                 }
             }
         }
     })
    def test_thermostat_control_schedule_change(self):
        # setup a thermostat
        self.hass.states.set(
            'thermostat.test1', '25.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })

        # setup a proximity zone
        self.hass.states.set(
            'proximity.test1', '0',
            {
                'dir_of_travel': 'unknown',
                'friendly_name': 'test1',
                'nearest': 'Nick',
                'unit_of_measurement': 'km'
            })

        # mimic properly formatted config.yaml entry
        assert thermostat_control.setup(self.hass, {
            'thermostat_control': {
                'test1': {
                    'schedule': {
                        '07:00': 21.5,
                        '10:15': 24.5,
                        '15:45': 23.5,
                        '16:45': 20.5
                    },
                    'max_temp': 26,
                    'min_temp': 15,
                    'proximity': {
                        'distance_offset': 0.1,
                        'away_distance': 50,
                        'zone': 'test1'
                    }
                }
            }
        })

        # ========= Time Change 1 =========
        # set the time of HA
        fire_time_changed(self.hass,
                          dt_util.utcnow().replace(hour=7, minute=0, second=0))
        self.hass.pool.block_till_done()

        # get the state of the created entity
        state = self.hass.states.get('thermostat_control.test1')

        # test the expected values of the thermostat_control entity
        self.assertEqual('21.5', state.state)
        self.assertEqual(21.5, state.attributes.get('set_temp'))
        self.assertEqual('07:00', state.attributes.get('active_from'))
        self.assertEqual('10:15', state.attributes.get('next_change'))
        self.assertEqual(21.5, state.attributes.get('schedule_temp'))
        self.assertEqual(0, state.attributes.get('offset_temp'))
        self.assertEqual('off', state.attributes.get('manual_override'))
        self.assertEqual('not set',
                         state.attributes.get('manual_override_end'))

        # test the value of the thermostat
        state = self.hass.states.get('thermostat.test1')

        # test the expected values of the thermostat entity
        self.assertEqual('21.5', state.state)

        # ========= Time Change 2 =========
        # set the time of HA
        fire_time_changed(self.hass,
                          dt_util.utcnow().replace(hour=10, minute=15,
                          second=0))
        self.hass.pool.block_till_done()

        # get the state of the created entity
        state = self.hass.states.get('thermostat_control.test1')

        # test the expected values of the thermostat_control entity
        self.assertEqual('24.5', state.state)
        self.assertEqual(24.5, state.attributes.get('set_temp'))
        self.assertEqual('10:15', state.attributes.get('active_from'))
        self.assertEqual('15:45', state.attributes.get('next_change'))
        self.assertEqual(24.5, state.attributes.get('schedule_temp'))

        # test the value of the thermostat
        state = self.hass.states.get('thermostat.test1')

        # test the expected values of the thermostat entity
        self.assertEqual('24.5', state.state)

        # ========= Time Change 3 =========
        # set the time of HA
        fire_time_changed(self.hass,
                          dt_util.utcnow().replace(hour=15, minute=45,
                          second=0))
        self.hass.pool.block_till_done()

        # get the state of the created entity
        state = self.hass.states.get('thermostat_control.test1')

        # test the expected values of the thermostat_control entity
        self.assertEqual('23.5', state.state)
        self.assertEqual(23.5, state.attributes.get('set_temp'))
        self.assertEqual('15:45', state.attributes.get('active_from'))
        self.assertEqual('16:45', state.attributes.get('next_change'))
        self.assertEqual(23.5, state.attributes.get('schedule_temp'))

        # test the value of the thermostat
        state = self.hass.states.get('thermostat.test1')

        # test the expected values of the thermostat entity
        self.assertEqual('23.5', state.state)

        # ========= Time Change 4 =========
        # set the time of HA
        fire_time_changed(self.hass,
                          dt_util.utcnow().replace(hour=16, minute=45,
                          second=0))
        self.hass.pool.block_till_done()

        # get the state of the created entity
        state = self.hass.states.get('thermostat_control.test1')

        # test the expected values of the thermostat_control entity
        self.assertEqual('20.5', state.state)
        self.assertEqual(20.5, state.attributes.get('set_temp'))
        self.assertEqual('16:45', state.attributes.get('active_from'))
        self.assertEqual('07:00', state.attributes.get('next_change'))
        self.assertEqual(20.5, state.attributes.get('schedule_temp'))

        # test the value of the thermostat
        state = self.hass.states.get('thermostat.test1')

        # test the expected values of the thermostat entity
        self.assertEqual('20.5', state.state)
    def test_thermostat_control_success(self):
        # setup a thermostat
        self.hass.states.set(
            'thermostat.test1', '25.5',
            {
                'away_mode': 'off',
                'current_operation': 'idle',
                'current_temperature': 19,
                'fan': 'off',
                'friendly_name': 'test1',
                'humidity': 38,
                'max_temp': 35,
                'min_temp': 16,
                'mode': 'heat',
                'target_humidity': 35,
                'target_temp_high': 16,
                'target_temp_low': 16,
                'temperature': 23.5,
                'unit_of_measurement': '°C'
            })

        # setup a proximity zone
        self.hass.states.set(
            'proximity.test1', '0',
            {
                'dir_of_travel': 'unknown',
                'friendly_name': 'test1',
                'nearest': 'Nick',
                'unit_of_measurement': 'km'
            })

        # mimic properly formatted config.yaml entry
        assert thermostat_control.setup(self.hass, {
            'thermostat_control': {
                'test1': {
                    'schedule': {
                        '07:00': 21.5,
                        '10:15': 24.5,
                        '15:45': 23.5,
                        '16:45': 20.5
                    },
                    'max_temp': 26,
                    'min_temp': 15,
                    'proximity': {
                        'distance_offset': 0.1,
                        'away_distance': 50,
                        'zone': 'test1'
                    }
                }
            }
        })

        # get the state of the created entity
        state = self.hass.states.get('thermostat_control.test1')

        # test the expected values of the entity
        self.assertEqual('20.5', state.state)
        self.assertEqual(20.5, state.attributes.get('set_temp'))
        self.assertEqual('16:45', state.attributes.get('active_from'))
        self.assertEqual('07:00', state.attributes.get('next_change'))
        self.assertEqual(20.5, state.attributes.get('schedule_temp'))
        self.assertEqual(0, state.attributes.get('offset_temp'))
        self.assertEqual('off', state.attributes.get('manual_override'))
        self.assertEqual('not set',
                         state.attributes.get('manual_override_end'))
        self.assertEqual('°C', state.attributes.get('unit_of_measurement'))
        self.assertEqual('test1', state.attributes.get('friendly_name'))