Esempio n. 1
0
    def test_device_tracker_test1_awayfurther_test2_in_ignored_zone(self):
        """Test for tracker states."""
        self.hass.states.set("device_tracker.test1", "not_home",
                             {"friendly_name": "test1"})
        self.hass.block_till_done()
        self.hass.states.set("device_tracker.test2", "work",
                             {"friendly_name": "test2"})
        self.hass.block_till_done()
        assert proximity.setup(
            self.hass,
            {
                "proximity": {
                    "home": {
                        "ignored_zones": ["work"],
                        "devices":
                        ["device_tracker.test1", "device_tracker.test2"],
                        "zone": "home",
                    }
                }
            },
        )

        self.hass.states.set(
            "device_tracker.test1",
            "not_home",
            {
                "friendly_name": "test1",
                "latitude": 20.1,
                "longitude": 10.1
            },
        )
        self.hass.block_till_done()
        state = self.hass.states.get("proximity.home")
        assert state.attributes.get("nearest") == "test1"
        assert state.attributes.get("dir_of_travel") == "unknown"
Esempio n. 2
0
 def test_device_trackers_in_zone(self):
     assert proximity.setup(self.hass, {
         'proximity': {
             'zone': 'home',
             'ignored_zones': {
                 'work'
             },
             'devices': {
                 'device_tracker.test1',
                 'device_tracker.test2'
             },
             'tolerance': '1'
         }
     })
     
     self.hass.states.set(
         'device_tracker.test1', 'home',
         {
             'friendly_name': 'test1',
             'latitude': 2.1,
             'longitude': 1.1
         })
     self.hass.pool.block_till_done()
     self.hass.states.set(
         'device_tracker.test2', 'home',
         {
             'friendly_name': 'test2',
             'latitude': 2.1,
             'longitude': 1.1
         })
     self.hass.pool.block_till_done()
     state = self.hass.states.get('proximity.home')
     assert state.state == '0'
     assert (state.attributes.get('nearest') == 'test1, test2') or (state.attributes.get('nearest') == 'test2, test1')
     assert state.attributes.get('dir_of_travel') == 'arrived'
Esempio n. 3
0
    def test_proximities(self):
        """Test a list of proximities."""
        assert proximity.setup(
            self.hass, {
                'proximity': [{
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices':
                    {'device_tracker.test1', 'device_tracker.test2'},
                    'tolerance': '1'
                }, {
                    'zone': 'work',
                    'devices': {'device_tracker.test1'},
                    'tolerance': '1'
                }]
            })

        proximities = ['home', 'work']

        for prox in proximities:
            state = self.hass.states.get('proximity.' + prox)
            assert state.state == 'not set'
            assert state.attributes.get('nearest') == 'not set'
            assert state.attributes.get('dir_of_travel') == 'not set'

            self.hass.states.set('proximity.' + prox, '0')
            self.hass.pool.block_till_done()
            state = self.hass.states.get('proximity.' + prox)
            assert state.state == '0'
Esempio n. 4
0
    def test_device_tracker_test1_awayfurther_test2_in_ignored_zone(self):
        """Test for tracker states."""
        self.hass.states.set('device_tracker.test1', 'not_home',
                             {'friendly_name': 'test1'})
        self.hass.block_till_done()
        self.hass.states.set('device_tracker.test2', 'work',
                             {'friendly_name': 'test2'})
        self.hass.block_till_done()
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'home': {
                        'ignored_zones': ['work'],
                        'devices':
                        ['device_tracker.test1', 'device_tracker.test2']
                    }
                }
            })

        self.hass.states.set('device_tracker.test1', 'not_home', {
            'friendly_name': 'test1',
            'latitude': 20.1,
            'longitude': 10.1
        })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'
Esempio n. 5
0
    def test_device_tracker_test1_awaycloser(self):
        """Test for tracker state away closer."""
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices': {'device_tracker.test1'}
                }
            })

        self.hass.states.set('device_tracker.test1', 'not_home', {
            'friendly_name': 'test1',
            'latitude': 40.1,
            'longitude': 20.1
        })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'
        self.hass.states.set('device_tracker.test1', 'not_home', {
            'friendly_name': 'test1',
            'latitude': 20.1,
            'longitude': 10.1
        })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'towards'
Esempio n. 6
0
    def test_device_trackers_in_zone(self):
        """Test for trackers in zone."""
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices':
                    {'device_tracker.test1', 'device_tracker.test2'},
                    'tolerance': '1'
                }
            })

        self.hass.states.set('device_tracker.test1', 'home', {
            'friendly_name': 'test1',
            'latitude': 2.1,
            'longitude': 1.1
        })
        self.hass.pool.block_till_done()
        self.hass.states.set('device_tracker.test2', 'home', {
            'friendly_name': 'test2',
            'latitude': 2.1,
            'longitude': 1.1
        })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.state == '0'
        assert ((state.attributes.get('nearest') == 'test1, test2')
                or (state.attributes.get('nearest') == 'test2, test1'))
        assert state.attributes.get('dir_of_travel') == 'arrived'
Esempio n. 7
0
    def test_device_tracker_test1_awayfurther_a_bit(self):
        """Test for tracker states."""
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices': {'device_tracker.test1'},
                    'tolerance': 1000
                }
            })

        self.hass.states.set(
            'device_tracker.test1', 'not_home', {
                'friendly_name': 'test1',
                'latitude': 20.1000001,
                'longitude': 10.1000001
            })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'
        self.hass.states.set(
            'device_tracker.test1', 'not_home', {
                'friendly_name': 'test1',
                'latitude': 20.1000002,
                'longitude': 10.1000002
            })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'stationary'
Esempio n. 8
0
    def test_device_tracker_test1_away(self):
        """Test for tracker state away."""
        assert proximity.setup(self.hass, {
            'proximity': {
                'zone': 'home',
                'ignored_zones': {
                    'work'
                },
                'devices': {
                    'device_tracker.test1'
                },
                'tolerance': '1'
            }
        })

        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1',
                'latitude': 20.1,
                'longitude': 10.1
            })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'
Esempio n. 9
0
    def test_proximity(self):
        """Test the proximity."""
        assert proximity.setup(self.hass, {
            'proximity': {
                'zone': 'home',
                'ignored_zones': {
                    'work'
                },
                'devices': {
                    'device_tracker.test1',
                    'device_tracker.test2'
                },
                'tolerance': '1'
            }
        })

        state = self.hass.states.get('proximity.home')
        assert state.state == 'not set'
        assert state.attributes.get('nearest') == 'not set'
        assert state.attributes.get('dir_of_travel') == 'not set'

        self.hass.states.set('proximity.home', '0')
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.state == '0'
Esempio n. 10
0
    def test_proximities(self):
        """Test a list of proximities."""
        assert proximity.setup(self.hass, {
            'proximity': [{
                'zone': 'home',
                'ignored_zones': {
                    'work'
                },
                'devices': {
                    'device_tracker.test1',
                    'device_tracker.test2'
                },
                'tolerance': '1'
            }, {
                'zone': 'work',
                'devices': {
                    'device_tracker.test1'
                },
                'tolerance': '1'
            }]
        })

        proximities = ['home', 'work']

        for prox in proximities:
            state = self.hass.states.get('proximity.' + prox)
            assert state.state == 'not set'
            assert state.attributes.get('nearest') == 'not set'
            assert state.attributes.get('dir_of_travel') == 'not set'

            self.hass.states.set('proximity.' + prox, '0')
            self.hass.pool.block_till_done()
            state = self.hass.states.get('proximity.' + prox)
            assert state.state == '0'
Esempio n. 11
0
    def test_proximity(self):
        """Test the proximity."""
        assert proximity.setup(self.hass, {
            'proximity': {
                'zone': 'home',
                'ignored_zones': {
                    'work'
                },
                'devices': {
                    'device_tracker.test1',
                    'device_tracker.test2'
                },
                'tolerance': '1'
            }
        })

        state = self.hass.states.get('proximity.home')
        assert state.state == 'not set'
        assert state.attributes.get('nearest') == 'not set'
        assert state.attributes.get('dir_of_travel') == 'not set'

        self.hass.states.set('proximity.home', '0')
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.state == '0'
Esempio n. 12
0
 def test_no_devices_in_config(self):
     assert not proximity.setup(
         self.hass, {
             'proximity': {
                 'zone': 'home',
                 'ignored_zones': {'work'},
                 'tolerance': '1'
             }
         })
Esempio n. 13
0
 def test_no_zone_in_config(self):
     assert proximity.setup(
         self.hass, {
             'proximity': {
                 'ignored_zones': {'work'},
                 'devices':
                 {'device_tracker.test1', 'device_tracker.test2'},
                 'tolerance': '1'
             }
         })
Esempio n. 14
0
 def test_no_devices_in_config(self):
     assert not proximity.setup(self.hass, {
         'proximity': {
             'zone': 'home',
             'ignored_zones': {
                 'work'
             },
             'tolerance': '1'
         }
     })
Esempio n. 15
0
 def test_no_devices_in_config(self):
     """Test for missing devices in configuration."""
     assert not proximity.setup(
         self.hass, {
             'proximity': {
                 'zone': 'home',
                 'ignored_zones': {'work'},
                 'tolerance': '1'
             }
         })
Esempio n. 16
0
 def test_no_ignored_zones_in_config(self):
     """Test for ignored zones in configuration."""
     assert proximity.setup(
         self.hass, {
             'proximity': {
                 'zone': 'home',
                 'devices':
                 {'device_tracker.test1', 'device_tracker.test2'},
                 'tolerance': '1'
             }
         })
Esempio n. 17
0
 def test_no_zone_in_config(self):
     """Test for missing zone in configuration."""
     assert proximity.setup(
         self.hass, {
             'proximity': {
                 'ignored_zones': {'work'},
                 'devices':
                 {'device_tracker.test1', 'device_tracker.test2'},
                 'tolerance': '1'
             }
         })
    def test_device_tracker_test1_awayfurther_than_test2_first_test1(self):
        """Test for tracker ordering."""
        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1'
            })
        self.hass.block_till_done()
        self.hass.states.set(
            'device_tracker.test2', 'not_home',
            {
                'friendly_name': 'test2'
            })
        self.hass.block_till_done()

        assert proximity.setup(self.hass, {
            'proximity': {
                'home': {
                    'ignored_zones': [
                        'work'
                    ],
                    'devices': [
                        'device_tracker.test1',
                        'device_tracker.test2'
                    ],
                    'tolerance': '1',
                    'zone': 'home'
                }
            }
        })

        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1',
                'latitude': 20.1,
                'longitude': 10.1
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'

        self.hass.states.set(
            'device_tracker.test2', 'not_home',
            {
                'friendly_name': 'test2',
                'latitude': 40.1,
                'longitude': 20.1
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'
Esempio n. 19
0
 def test_no_devices_in_config(self):
     """Test for missing devices in configuration."""
     assert not proximity.setup(self.hass, {
         'proximity': {
             'zone': 'home',
             'ignored_zones': {
                 'work'
             },
             'tolerance': '1'
         }
     })
Esempio n. 20
0
 def test_no_ignored_zones_in_config(self):
     assert proximity.setup(self.hass, {
         'proximity': {
             'zone': 'home',
             'devices': {
                 'device_tracker.test1',
                 'device_tracker.test2'
             },
             'tolerance': '1'
         }
     })
Esempio n. 21
0
 def test_no_zone_in_config(self):
     """Test for missing zone in configuration."""
     assert proximity.setup(self.hass, {
         'proximity': {
             'ignored_zones': {
                 'work'
             },
             'devices': {
                 'device_tracker.test1',
                 'device_tracker.test2'
             },
             'tolerance': '1'
         }
     })
Esempio n. 22
0
    def test_device_tracker_test1_awayfurther_than_test2_first_test1_than_test2_than_test1(
            self):
        self.hass.states.set('device_tracker.test1', 'not_home',
                             {'friendly_name': 'test1'})
        self.hass.pool.block_till_done()
        self.hass.states.set('device_tracker.test2', 'not_home',
                             {'friendly_name': 'test2'})
        self.hass.pool.block_till_done()
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices':
                    {'device_tracker.test1', 'device_tracker.test2'}
                }
            })

        self.hass.states.set('device_tracker.test1', 'not_home', {
            'friendly_name': 'test1',
            'latitude': 10.1,
            'longitude': 5.1
        })
        self.hass.pool.block_till_done()

        self.hass.states.set('device_tracker.test2', 'not_home', {
            'friendly_name': 'test2',
            'latitude': 20.1,
            'longitude': 10.1
        })
        self.hass.pool.block_till_done()
        self.hass.states.set('device_tracker.test1', 'not_home', {
            'friendly_name': 'test1',
            'latitude': 40.1,
            'longitude': 20.1
        })
        self.hass.pool.block_till_done()
        self.hass.states.set('device_tracker.test1', 'not_home', {
            'friendly_name': 'test1',
            'latitude': 35.1,
            'longitude': 15.1
        })
        self.hass.pool.block_till_done()
        self.hass.states.set('device_tracker.test1', 'work',
                             {'friendly_name': 'test1'})
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test2'
        assert state.attributes.get('dir_of_travel') == 'unknown'
Esempio n. 23
0
 def test_proximities_missing_devices(self):
     """Test a list of proximities with one missing devices."""
     assert not proximity.setup(
         self.hass, {
             'proximity': [{
                 'zone': 'home',
                 'ignored_zones': {'work'},
                 'devices':
                 {'device_tracker.test1', 'device_tracker.test2'},
                 'tolerance': '1'
             }, {
                 'zone': 'work',
                 'tolerance': '1'
             }]
         })
Esempio n. 24
0
 def test_device_tracker_test1_awayfurther_than_test2_first_test2(self):
     self.hass.states.set(
         'device_tracker.test1', 'not_home',
         {
             'friendly_name': 'test1'
         })
     self.hass.pool.block_till_done()
     self.hass.states.set(
         'device_tracker.test2', 'not_home',
         {
             'friendly_name': 'test2'
         })
     self.hass.pool.block_till_done()
     assert proximity.setup(self.hass, {
         'proximity': {
             'zone': 'home',
             'ignored_zones': {
                 'work'
             },
             'devices': {
                 'device_tracker.test1',
                 'device_tracker.test2'
             }
         }
     })
     
     self.hass.states.set(
         'device_tracker.test2', 'not_home',
         {
             'friendly_name': 'test2',
             'latitude': 40.1,
             'longitude': 20.1
         })
     self.hass.pool.block_till_done()
     state = self.hass.states.get('proximity.home')
     assert state.attributes.get('nearest') == 'test2'
     assert state.attributes.get('dir_of_travel') == 'unknown'
     self.hass.states.set(
         'device_tracker.test1', 'not_home',
         {
             'friendly_name': 'test1',
             'latitude': 20.1,
             'longitude': 10.1
         })
     self.hass.pool.block_till_done()
     state = self.hass.states.get('proximity.home')
     assert state.attributes.get('nearest') == 'test1'
     assert state.attributes.get('dir_of_travel') == 'unknown'
Esempio n. 25
0
    def test_device_tracker_test1_no_coordinates(self):
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices': {'device_tracker.test1'},
                    'tolerance': '1'
                }
            })

        self.hass.states.set('device_tracker.test1', 'not_home',
                             {'friendly_name': 'test1'})
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'not set'
        assert state.attributes.get('dir_of_travel') == 'not set'
Esempio n. 26
0
 def test_proximities_missing_devices(self):
     """Test a list of proximities with one missing devices."""
     assert not proximity.setup(self.hass, {
         'proximity': [{
             'zone': 'home',
             'ignored_zones': {
                 'work'
             },
             'devices': {
                 'device_tracker.test1',
                 'device_tracker.test2'
             },
             'tolerance': '1'
         }, {
             'zone': 'work',
             'tolerance': '1'
         }]
     })
Esempio n. 27
0
    def test_all_device_trackers_in_ignored_zone(self):
        """Test for tracker in ignored zone."""
        assert proximity.setup(
            self.hass, {
                'proximity': {
                    'zone': 'home',
                    'ignored_zones': {'work'},
                    'devices': {'device_tracker.test1'}
                }
            })

        self.hass.states.set('device_tracker.test1', 'work',
                             {'friendly_name': 'test1'})
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.state == 'not set'
        assert state.attributes.get('nearest') == 'not set'
        assert state.attributes.get('dir_of_travel') == 'not set'
    def test_device_tracker_test1_awayfurther_a_bit(self):
        """Test for tracker states."""
        assert proximity.setup(self.hass, {
            'proximity': {
                'home': {
                    'ignored_zones': [
                        'work'
                    ],
                    'devices': [
                        'device_tracker.test1'
                    ],
                    'tolerance': 1000,
                    'zone': 'home'
                }
            }
        })

        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1',
                'latitude': 20.1000001,
                'longitude': 10.1000001
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'

        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1',
                'latitude': 20.1000002,
                'longitude': 10.1000002
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'stationary'
Esempio n. 29
0
 def test_device_tracker_test1_no_coordinates(self):
     assert proximity.setup(self.hass, {
         'proximity': {
             'zone': 'home',
             'ignored_zones': {
                 'work'
             },
             'devices': {
                 'device_tracker.test1'
             },
             'tolerance': '1'
         }
     })
     
     self.hass.states.set(
         'device_tracker.test1', 'not_home',
         {
             'friendly_name': 'test1'
         })
     self.hass.pool.block_till_done()
     state = self.hass.states.get('proximity.home')
     assert state.attributes.get('nearest') == 'not set'
     assert state.attributes.get('dir_of_travel') == 'not set'
Esempio n. 30
0
    def test_all_device_trackers_in_ignored_zone(self):
        """Test for tracker in ignored zone."""
        assert proximity.setup(self.hass, {
            'proximity': {
                'zone': 'home',
                'ignored_zones': {
                    'work'
                },
                'devices': {
                    'device_tracker.test1'
                }
            }
        })

        self.hass.states.set(
            'device_tracker.test1', 'work',
            {
                'friendly_name': 'test1'
            })
        self.hass.pool.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.state == 'not set'
        assert state.attributes.get('nearest') == 'not set'
        assert state.attributes.get('dir_of_travel') == 'not set'
Esempio n. 31
0
    def test_device_tracker_test1_nearest_after_test2_in_ignored_zone(self):
        """Test for tracker states."""
        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1'
            })
        self.hass.block_till_done()
        self.hass.states.set(
            'device_tracker.test2', 'not_home',
            {
                'friendly_name': 'test2'
            })
        self.hass.block_till_done()

        assert proximity.setup(self.hass, {
            'proximity': {
                'home': {
                    'ignored_zones': [
                        'work'
                    ],
                    'devices': [
                        'device_tracker.test1',
                        'device_tracker.test2'
                    ]
                }
            }
        })

        self.hass.states.set(
            'device_tracker.test1', 'not_home',
            {
                'friendly_name': 'test1',
                'latitude': 20.1,
                'longitude': 10.1
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'

        self.hass.states.set(
            'device_tracker.test2', 'not_home',
            {
                'friendly_name': 'test2',
                'latitude': 10.1,
                'longitude': 5.1
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test2'
        assert state.attributes.get('dir_of_travel') == 'unknown'

        self.hass.states.set(
            'device_tracker.test2', 'work',
            {
                'friendly_name': 'test2',
                'latitude': 12.6,
                'longitude': 7.6
            })
        self.hass.block_till_done()
        state = self.hass.states.get('proximity.home')
        assert state.attributes.get('nearest') == 'test1'
        assert state.attributes.get('dir_of_travel') == 'unknown'