def setUpModule():  # pylint: disable=invalid-name
    """Write a device tracker known devices file to be used."""
    device_tracker.update_config(
        KNOWN_DEV_YAML_PATH, 'device_1',
        device_tracker.Device(None,
                              None,
                              None,
                              True,
                              'device_1',
                              'DEV1',
                              picture='http://example.com/dev1.jpg'))

    device_tracker.update_config(
        KNOWN_DEV_YAML_PATH, 'device_2',
        device_tracker.Device(None,
                              None,
                              None,
                              True,
                              'device_2',
                              'DEV2',
                              picture='http://example.com/dev2.jpg'))
Exemplo n.º 2
0
 def test_reading_yaml_config(self):
     """Test the rendering of the YAML configuration."""
     dev_id = 'test'
     device = device_tracker.Device(
         self.hass, timedelta(seconds=180), 0, True, dev_id,
         'AB:CD:EF:GH:IJ', 'Test name', 'http://test.picture', True)
     device_tracker.update_config(self.yaml_devices, dev_id, device)
     self.assertTrue(device_tracker.setup(self.hass, {}))
     config = device_tracker.load_config(self.yaml_devices, self.hass,
                                         device.consider_home, 0)[0]
     self.assertEqual(device.dev_id, config.dev_id)
     self.assertEqual(device.track, config.track)
     self.assertEqual(device.mac, config.mac)
     self.assertEqual(device.config_picture, config.config_picture)
     self.assertEqual(device.away_hide, config.away_hide)
     self.assertEqual(device.consider_home, config.consider_home)
Exemplo n.º 3
0
    def test_device_hidden(self):
        """Test hidden devices."""
        dev_id = 'test_entity'
        entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
        device = device_tracker.Device(
            self.hass, timedelta(seconds=180), 0, True, dev_id, None,
            away_hide=True)
        device_tracker.update_config(self.yaml_devices, dev_id, device)

        scanner = get_component('device_tracker.test').SCANNER
        scanner.reset()

        self.assertTrue(device_tracker.setup(self.hass, {
            device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}))

        self.assertTrue(self.hass.states.get(entity_id)
                            .attributes.get(ATTR_HIDDEN))
Exemplo n.º 4
0
    def test_entity_attributes(self):
        """Test the entity attributes."""
        dev_id = 'test_entity'
        entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
        friendly_name = 'Paulus'
        picture = 'http://placehold.it/200x200'

        device = device_tracker.Device(
            self.hass, timedelta(seconds=180), 0, True, dev_id, None,
            friendly_name, picture, away_hide=True)
        device_tracker.update_config(self.yaml_devices, dev_id, device)

        self.assertTrue(device_tracker.setup(self.hass, {}))

        attrs = self.hass.states.get(entity_id).attributes

        self.assertEqual(friendly_name, attrs.get(ATTR_FRIENDLY_NAME))
        self.assertEqual(picture, attrs.get(ATTR_ENTITY_PICTURE))
Exemplo n.º 5
0
    def test_group_all_devices(self):
        """Test grouping of devices."""
        dev_id = 'test_entity'
        entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
        device = device_tracker.Device(
            self.hass, timedelta(seconds=180), 0, True, dev_id, None,
            away_hide=True)
        device_tracker.update_config(self.yaml_devices, dev_id, device)

        scanner = get_component('device_tracker.test').SCANNER
        scanner.reset()

        self.assertTrue(device_tracker.setup(self.hass, {
            device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}))

        state = self.hass.states.get(device_tracker.ENTITY_ID_ALL_DEVICES)
        self.assertIsNotNone(state)
        self.assertEqual(STATE_NOT_HOME, state.state)
        self.assertSequenceEqual((entity_id,),
                                 state.attributes.get(ATTR_ENTITY_ID))