Example #1
0
def melissa_mock():
    """Use this to mock the melissa api."""
    api = Mock()
    api.async_fetch_devices = mock_coro_func(
        return_value=json.loads(load_fixture('melissa_fetch_devices.json')))
    api.async_status = mock_coro_func(return_value=json.loads(load_fixture(
        'melissa_status.json')))
    api.async_cur_settings = mock_coro_func(
        return_value=json.loads(load_fixture('melissa_cur_settings.json')))

    api.async_send = mock_coro_func(return_value=True)

    api.STATE_OFF = 0
    api.STATE_ON = 1
    api.STATE_IDLE = 2

    api.MODE_AUTO = 0
    api.MODE_FAN = 1
    api.MODE_HEAT = 2
    api.MODE_COOL = 3
    api.MODE_DRY = 4

    api.FAN_AUTO = 0
    api.FAN_LOW = 1
    api.FAN_MEDIUM = 2
    api.FAN_HIGH = 3

    api.STATE = 'state'
    api.MODE = 'mode'
    api.FAN = 'fan'
    api.TEMP = 'temp'
    return api
Example #2
0
    def test_service_face(self, camera_mock, aioclient_mock):
        """Set up component, test person face services."""
        aioclient_mock.get(
            self.endpoint_url.format("persongroups"),
            text=load_fixture('microsoft_face_persongroups.json')
        )
        aioclient_mock.get(
            self.endpoint_url.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )
        aioclient_mock.get(
            self.endpoint_url.format("persongroups/test_group2/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )

        self.config['camera'] = {'platform': 'demo'}
        with assert_setup_component(3, mf.DOMAIN):
            setup_component(self.hass, mf.DOMAIN, self.config)

        assert len(aioclient_mock.mock_calls) == 3

        aioclient_mock.post(
            self.endpoint_url.format(
                "persongroups/test_group2/persons/"
                "2ae4935b-9659-44c3-977f-61fac20d0538/persistedFaces"),
            status=200, text="{}"
        )

        face_person(
            self.hass, 'test_group2', 'David', 'camera.demo_camera')
        self.hass.block_till_done()

        assert len(aioclient_mock.mock_calls) == 4
        assert aioclient_mock.mock_calls[3][2] == b'Test'
Example #3
0
    def test_setup_component_test_entities(self, aioclient_mock):
        """Set up component."""
        aioclient_mock.get(
            self.endpoint_url.format("persongroups"),
            text=load_fixture('microsoft_face_persongroups.json')
        )
        aioclient_mock.get(
            self.endpoint_url.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )
        aioclient_mock.get(
            self.endpoint_url.format("persongroups/test_group2/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )

        with assert_setup_component(3, mf.DOMAIN):
            setup_component(self.hass, mf.DOMAIN, self.config)

        assert len(aioclient_mock.mock_calls) == 3

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')
        entity_group2 = self.hass.states.get('microsoft_face.test_group2')

        assert entity_group1 is not None
        assert entity_group2 is not None

        assert entity_group1.attributes['Ryan'] == \
            '25985303-c537-4467-b41d-bdb45cd95ca1'
        assert entity_group1.attributes['David'] == \
            '2ae4935b-9659-44c3-977f-61fac20d0538'

        assert entity_group2.attributes['Ryan'] == \
            '25985303-c537-4467-b41d-bdb45cd95ca1'
        assert entity_group2.attributes['David'] == \
            '2ae4935b-9659-44c3-977f-61fac20d0538'
Example #4
0
    def test_scan_devices(self):
        """Test creating device info (MAC, name) from response.

        The created known_devices.yaml device info is compared
        to the DD-WRT Lan Status request response fixture.
        This effectively checks the data parsing functions.
        """
        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                'GET', r'http://%s/Status_Wireless.live.asp' % TEST_HOST,
                text=load_fixture('Ddwrt_Status_Wireless.txt'))
            mock_request.register_uri(
                'GET', r'http://%s/Status_Lan.live.asp' % TEST_HOST,
                text=load_fixture('Ddwrt_Status_Lan.txt'))

            with assert_setup_component(1):
                assert setup_component(
                    self.hass, DOMAIN, {DOMAIN: {
                        CONF_PLATFORM: 'ddwrt',
                        CONF_HOST: TEST_HOST,
                        CONF_USERNAME: '******',
                        CONF_PASSWORD: '******'
                    }})
                self.hass.block_till_done()

            path = self.hass.config.path(device_tracker.YAML_DEVICES)
            devices = config.load_yaml_config_file(path)
            for device in devices:
                self.assertIn(
                    devices[device]['mac'],
                    load_fixture('Ddwrt_Status_Lan.txt'))
                self.assertIn(
                    slugify(devices[device]['name']),
                    load_fixture('Ddwrt_Status_Lan.txt'))
Example #5
0
    def test_device_name_no_dhcp(self):
        """Test creating device info (MAC) when missing dhcp response."""
        with requests_mock.Mocker() as mock_request:
            mock_request.register_uri(
                'GET', r'http://%s/Status_Wireless.live.asp' % TEST_HOST,
                text=load_fixture('Ddwrt_Status_Wireless.txt'))
            mock_request.register_uri(
                'GET', r'http://%s/Status_Lan.live.asp' % TEST_HOST,
                text=load_fixture('Ddwrt_Status_Lan.txt').
                replace('dhcp_leases', 'missing'))

            with assert_setup_component(1):
                assert setup_component(
                    self.hass, DOMAIN, {DOMAIN: {
                        CONF_PLATFORM: 'ddwrt',
                        CONF_HOST: TEST_HOST,
                        CONF_USERNAME: '******',
                        CONF_PASSWORD: '******'
                    }})
                self.hass.block_till_done()

            path = self.hass.config.path(device_tracker.YAML_DEVICES)
            devices = config.load_yaml_config_file(path)
            for device in devices:
                _LOGGER.error(devices[device])
                self.assertIn(
                    devices[device]['mac'],
                    load_fixture('Ddwrt_Status_Lan.txt'))
    def test_invalid_sensors(self, mock):
        """Test the VultrBinarySensor fails."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        with patch(
            'vultr.Vultr.server_list',
            return_value=json.loads(
                load_fixture('vultr_server_list.json'))):
            # Setup hub
            base_vultr.setup(self.hass, VALID_CONFIG)

        bad_conf = {}  # No subscription

        no_subs_setup = vultr.setup_platform(self.hass,
                                             bad_conf,
                                             self.add_entities,
                                             None)

        self.assertFalse(no_subs_setup)

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: '555555'
        }  # Sub not associated with API key (not in server_list)

        wrong_subs_setup = vultr.setup_platform(self.hass,
                                                bad_conf,
                                                self.add_entities,
                                                None)

        self.assertFalse(wrong_subs_setup)
    def test_invalid_switches(self, mock):
        """Test the VultrSwitch fails."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        mock.get(
            'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_server_list.json'))

        base_vultr.setup(self.hass, VALID_CONFIG)

        bad_conf = {}  # No subscription

        no_subs_setup = vultr.setup_platform(self.hass,
                                             bad_conf,
                                             self.add_devices,
                                             None)

        self.assertIsNotNone(no_subs_setup)

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: '665544'
        }  # Sub not associated with API key (not in server_list)

        wrong_subs_setup = vultr.setup_platform(self.hass,
                                                bad_conf,
                                                self.add_devices,
                                                None)

        self.assertIsNotNone(wrong_subs_setup)
Example #8
0
    def test_binary_sensor(self, mock):
        """Test the Ring sensor class and methods."""
        mock.post('https://oauth.ring.com/oauth/token',
                  text=load_fixture('ring_oauth.json'))
        mock.post('https://api.ring.com/clients_api/session',
                  text=load_fixture('ring_session.json'))
        mock.get('https://api.ring.com/clients_api/ring_devices',
                 text=load_fixture('ring_devices.json'))
        mock.get('https://api.ring.com/clients_api/dings/active',
                 text=load_fixture('ring_ding_active.json'))
        mock.get('https://api.ring.com/clients_api/doorbots/987652/health',
                 text=load_fixture('ring_doorboot_health_attrs.json'))

        base_ring.setup(self.hass, VALID_CONFIG)
        ring.setup_platform(self.hass,
                            self.config,
                            self.add_devices,
                            None)

        for device in self.DEVICES:
            device.update()
            if device.name == 'Front Door Ding':
                self.assertEqual('on', device.state)
                self.assertEqual('America/New_York',
                                 device.device_state_attributes['timezone'])
            elif device.name == 'Front Door Motion':
                self.assertEqual('off', device.state)
                self.assertEqual('motion', device.device_class)

            self.assertIsNone(device.entity_picture)
            self.assertEqual(ATTRIBUTION,
                             device.device_state_attributes['attribution'])
Example #9
0
 def test_setup(self, mock):
     """Test the setup."""
     mock.post('https://oauth.ring.com/oauth/token',
               text=load_fixture('ring_oauth.json'))
     mock.post('https://api.ring.com/clients_api/session',
               text=load_fixture('ring_session.json'))
     response = ring.setup(self.hass, self.config)
     self.assertTrue(response)
Example #10
0
    def test_sensor(self, mock):
        """Test the Ring senskor class and methods."""
        mock.post('https://api.ring.com/clients_api/session',
                  text=load_fixture('ring_session.json'))
        mock.get('https://api.ring.com/clients_api/ring_devices',
                 text=load_fixture('ring_devices.json'))
        mock.get('https://api.ring.com/clients_api/doorbots/987652/history',
                 text=load_fixture('ring_doorbots.json'))
        mock.get('https://api.ring.com/clients_api/doorbots/987652/health',
                 text=load_fixture('ring_doorboot_health_attrs.json'))
        mock.get('https://api.ring.com/clients_api/chimes/999999/health',
                 text=load_fixture('ring_chime_health_attrs.json'))
        base_ring.setup(self.hass, VALID_CONFIG)
        ring.setup_platform(self.hass,
                            self.config,
                            self.add_devices,
                            None)

        for device in self.DEVICES:
            device.update()
            if device.name == 'Front Battery':
                self.assertEqual(80, device.state)
                self.assertEqual('hp_cam_v1',
                                 device.device_state_attributes['kind'])
                self.assertEqual('stickup_cams',
                                 device.device_state_attributes['type'])
            if device.name == 'Front Door Battery':
                self.assertEqual(100, device.state)
                self.assertEqual('lpd_v1',
                                 device.device_state_attributes['kind'])
                self.assertNotEqual('chimes',
                                    device.device_state_attributes['type'])
            if device.name == 'Downstairs Volume':
                self.assertEqual(2, device.state)
                self.assertEqual('1.2.3',
                                 device.device_state_attributes['firmware'])
                self.assertEqual('ring_mock_wifi',
                                 device.device_state_attributes['wifi_name'])
                self.assertEqual('mdi:bell-ring', device.icon)
                self.assertEqual('chimes',
                                 device.device_state_attributes['type'])
            if device.name == 'Front Door Last Activity':
                self.assertFalse(device.device_state_attributes['answered'])
                self.assertEqual('America/New_York',
                                 device.device_state_attributes['timezone'])

            if device.name == 'Downstairs WiFi Signal Strength':
                self.assertEqual(-39, device.state)

            if device.name == 'Front Door WiFi Signal Category':
                self.assertEqual('good', device.state)

            if device.name == 'Front Door WiFi Signal Strength':
                self.assertEqual(-58, device.state)

            self.assertIsNone(device.entity_picture)
            self.assertEqual(ATTRIBUTION,
                             device.device_state_attributes['attribution'])
    def test_ms_identify_process_image(self, poll_mock, aioclient_mock):
        """Setup and scan a picture and test plates from event."""
        aioclient_mock.get(
            mf.FACE_API_URL.format("persongroups"),
            text=load_fixture('microsoft_face_persongroups.json')
        )
        aioclient_mock.get(
            mf.FACE_API_URL.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )
        aioclient_mock.get(
            mf.FACE_API_URL.format("persongroups/test_group2/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )

        setup_component(self.hass, ip.DOMAIN, self.config)

        state = self.hass.states.get('camera.demo_camera')
        url = "{0}{1}".format(
            self.hass.config.api.base_url,
            state.attributes.get(ATTR_ENTITY_PICTURE))

        face_events = []

        @callback
        def mock_face_event(event):
            """Mock event."""
            face_events.append(event)

        self.hass.bus.listen('image_processing.detect_face', mock_face_event)

        aioclient_mock.get(url, content=b'image')

        aioclient_mock.post(
            mf.FACE_API_URL.format("detect"),
            text=load_fixture('microsoft_face_detect.json')
        )
        aioclient_mock.post(
            mf.FACE_API_URL.format("identify"),
            text=load_fixture('microsoft_face_identify.json')
        )

        ip.scan(self.hass, entity_id='image_processing.test_local')
        self.hass.block_till_done()

        state = self.hass.states.get('image_processing.test_local')

        assert len(face_events) == 1
        assert state.attributes.get('total_faces') == 2
        assert state.state == 'David'

        assert face_events[0].data['name'] == 'David'
        assert face_events[0].data['confidence'] == float(92)
        assert face_events[0].data['entity_id'] == \
            'image_processing.test_local'
    def test_setup(self, mock):
        """Test successful setup."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))
        mock.get(
            'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_server_list.json'))

        response = vultr.setup(self.hass, self.config)
        self.assertTrue(response)
Example #13
0
def melissa_mock():
    """Use this to mock the melissa api."""
    api = Mock()
    api.async_fetch_devices = mock_coro_func(
        return_value=json.loads(load_fixture('melissa_fetch_devices.json')))
    api.async_status = mock_coro_func(return_value=json.loads(load_fixture(
        'melissa_status.json'
    )))

    api.TEMP = 'temp'
    api.HUMIDITY = 'humidity'
    return api
def mock_responses(mock):
    base_url = 'https://api.sleepiq.sleepnumber.com/rest/'
    mock.put(
        base_url + 'login',
        text=load_fixture('sleepiq-login.json'))
    mock.get(
        base_url + 'bed?_k=0987',
        text=load_fixture('sleepiq-bed.json'))
    mock.get(
        base_url + 'sleeper?_k=0987',
        text=load_fixture('sleepiq-sleeper.json'))
    mock.get(
        base_url + 'bed/familyStatus?_k=0987',
        text=load_fixture('sleepiq-familystatus.json'))
Example #15
0
    def test_service_person(self, aioclient_mock):
        """Set up component, test person services."""
        aioclient_mock.get(
            self.endpoint_url.format("persongroups"),
            text=load_fixture('microsoft_face_persongroups.json')
        )
        aioclient_mock.get(
            self.endpoint_url.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )
        aioclient_mock.get(
            self.endpoint_url.format("persongroups/test_group2/persons"),
            text=load_fixture('microsoft_face_persons.json')
        )

        with assert_setup_component(3, mf.DOMAIN):
            setup_component(self.hass, mf.DOMAIN, self.config)

        assert len(aioclient_mock.mock_calls) == 3

        aioclient_mock.post(
            self.endpoint_url.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_create_person.json')
        )
        aioclient_mock.delete(
            self.endpoint_url.format(
                "persongroups/test_group1/persons/"
                "25985303-c537-4467-b41d-bdb45cd95ca1"),
            status=200, text="{}"
        )

        create_person(self.hass, 'test group1', 'Hans')
        self.hass.block_till_done()

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')

        assert len(aioclient_mock.mock_calls) == 4
        assert entity_group1 is not None
        assert entity_group1.attributes['Hans'] == \
            '25985303-c537-4467-b41d-bdb45cd95ca1'

        delete_person(self.hass, 'test group1', 'Hans')
        self.hass.block_till_done()

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')

        assert len(aioclient_mock.mock_calls) == 5
        assert entity_group1 is not None
        assert 'Hans' not in entity_group1.attributes
Example #16
0
def mocked_requests(*args, **kwargs):
    """Mock requests.get invocations."""
    class MockResponse:
        """Class to represent a mocked response."""

        def __init__(self, json_data, status_code):
            """Initialize the mock response class."""
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            """Return the json of the response."""
            return self.json_data

        @property
        def content(self):
            """Return the content of the response."""
            return self.json()

        def raise_for_status(self):
            """Raise an HTTPError if status is not 200."""
            if self.status_code != 200:
                raise requests.HTTPError(self.status_code)

    url = urlparse(args[0])
    if re.match(r'^/fwo/[\w]+/[\w.]+\.json', url.path):
        return MockResponse(json.loads(load_fixture('bom_weather.json')), 200)

    raise NotImplementedError('Unknown route {}'.format(url.path))
Example #17
0
 def test_setup_component_no_login(self, mock):
     """Test the setup when no login is configured."""
     mock.post('https://api.ring.com/clients_api/session',
               text=load_fixture('ring_session.json'))
     conf = deepcopy(VALID_CONFIG)
     del conf['ring']['username']
     assert not setup.setup_component(self.hass, ring.DOMAIN, conf)
    def test_setup_and_initial_state(self, mock_req):
        """Test that the component is created and initialized as expected."""
        uri = re.compile(
            r"http://services\.swpc\.noaa\.gov/text/aurora-nowcast-map\.txt"
        )
        mock_req.get(uri, text=load_fixture('aurora.txt'))

        entities = []

        def mock_add_entities(new_entities, update_before_add=False):
            """Mock add entities."""
            if update_before_add:
                for entity in new_entities:
                    entity.update()

            for entity in new_entities:
                entities.append(entity)

        config = {
            "name": "Test",
            "forecast_threshold": 75
        }
        aurora.setup_platform(self.hass, config, mock_add_entities)

        aurora_component = entities[0]
        assert len(entities) == 1
        assert aurora_component.name == "Test"
        assert \
            aurora_component.device_state_attributes["visibility_level"] == '0'
        assert aurora_component.device_state_attributes["message"] == \
            "nothing's out"
        assert not aurora_component.is_on
    def test_custom_threshold_works(self, mock_req):
        """Test that the config can take a custom forecast threshold."""
        uri = re.compile(
            r"http://services\.swpc\.noaa\.gov/text/aurora-nowcast-map\.txt"
        )
        mock_req.get(uri, text=load_fixture('aurora.txt'))

        entities = []

        def mock_add_entities(new_entities, update_before_add=False):
            """Mock add entities."""
            if update_before_add:
                for entity in new_entities:
                    entity.update()

            for entity in new_entities:
                entities.append(entity)

        config = {
            "name": "Test",
            "forecast_threshold": 1
        }
        self.hass.config.longitude = 5
        self.hass.config.latitude = 5

        aurora.setup_platform(self.hass, config, mock_add_entities)

        aurora_component = entities[0]
        assert aurora_component.aurora_data.visibility_level == '5'
        assert aurora_component.is_on
    def test_openalpr_process_image(self, aioclient_mock):
        """Set up and scan a picture and test plates from event."""
        aioclient_mock.post(
            OPENALPR_API_URL, params=self.params,
            text=load_fixture('alpr_cloud.json'), status=200
        )

        with patch('homeassistant.components.camera.async_get_image',
                   return_value=mock_coro(
                       camera.Image('image/jpeg', b'image'))):
            ip.scan(self.hass, entity_id='image_processing.test_local')
            self.hass.block_till_done()

        state = self.hass.states.get('image_processing.test_local')

        assert len(aioclient_mock.mock_calls) == 1
        assert len(self.alpr_events) == 5
        assert state.attributes.get('vehicles') == 1
        assert state.state == 'H786P0J'

        event_data = [event.data for event in self.alpr_events if
                      event.data.get('plate') == 'H786P0J']
        assert len(event_data) == 1
        assert event_data[0]['plate'] == 'H786P0J'
        assert event_data[0]['confidence'] == float(90.436699)
        assert event_data[0]['entity_id'] == \
            'image_processing.test_local'
Example #21
0
def test_setup_pws(hass, aioclient_mock):
    """Test that the component is loaded with PWS id."""
    aioclient_mock.get(PWS_URL, text=load_fixture('wunderground-valid.json'))

    with assert_setup_component(1, 'sensor'):
        yield from async_setup_component(hass, 'sensor',
                                         {'sensor': VALID_CONFIG_PWS})
Example #22
0
 def test_setup_component_no_pwd(self, mock):
     """Test the setup when no password is configured."""
     mock.post('https://api.ring.com/clients_api/session',
               text=load_fixture('ring_session.json'))
     conf = self.config.copy()
     del conf['ring']['password']
     assert not setup.setup_component(self.hass, ring.DOMAIN, conf)
    def test_update_sensor_with_category(self):
        """Test updating sensor object."""
        raw_data = load_fixture('geo_rss_events.xml')
        # Loading raw data from fixture and plug in to data object as URL
        # works since the third-party feedparser library accepts a URL
        # as well as the actual data.
        data = self.setup_data(raw_data)
        category = "Category 1"
        name = "Name 1"
        unit_of_measurement = "Unit 1"
        sensor = geo_rss_events.GeoRssServiceSensor(category,
                                                    data, name,
                                                    unit_of_measurement)

        sensor.update()
        assert sensor.name == "Name 1 Category 1"
        assert sensor.unit_of_measurement == "Unit 1"
        assert sensor.icon == "mdi:alert"
        assert len(sensor._data.events) == 4
        assert sensor.state == 1
        assert sensor.device_state_attributes == {'Title 1': "117km"}
        # Check entries of first hit
        assert sensor._data.events[0][geo_rss_events.ATTR_TITLE] == "Title 1"
        assert sensor._data.events[0][
                   geo_rss_events.ATTR_CATEGORY] == "Category 1"
        self.assertAlmostEqual(sensor._data.events[0][
                                   geo_rss_events.ATTR_DISTANCE], 116.586, 0)
async def test_scan_devices(hass, aioclient_mock):
    """Set up a upc platform and scan device."""
    aioclient_mock.get(
        "http://{}/common_page/login.html".format(HOST),
        cookies={'sessionToken': '654321'}
    )
    aioclient_mock.post(
        "http://{}/xml/getter.xml".format(HOST),
        content=b'successful',
        cookies={'sessionToken': '654321'}
    )

    scanner = await platform.async_get_scanner(
        hass, {
            DOMAIN: {CONF_PLATFORM: 'upc_connect', CONF_HOST: HOST}})

    assert len(aioclient_mock.mock_calls) == 1

    aioclient_mock.clear_requests()
    aioclient_mock.post(
        "http://{}/xml/getter.xml".format(HOST),
        text=load_fixture('upc_connect.xml'),
        cookies={'sessionToken': '1235678'}
    )

    mac_list = await scanner.async_scan_devices()

    assert len(aioclient_mock.mock_calls) == 1
    assert aioclient_mock.mock_calls[0][2] == 'token=654321&fun=123'
    assert mac_list == ['30:D3:2D:0:69:21', '5C:AA:FD:25:32:02',
                        '70:EE:50:27:A1:38']
    def test_openalpr_process_image(self, aioclient_mock):
        """Setup and scan a picture and test plates from event."""
        aioclient_mock.get(self.url, content=b'image')
        aioclient_mock.post(
            OPENALPR_API_URL, params=self.params,
            text=load_fixture('alpr_cloud.json'), status=200
        )

        ip.scan(self.hass, entity_id='image_processing.test_local')
        self.hass.block_till_done()

        state = self.hass.states.get('image_processing.test_local')

        assert len(aioclient_mock.mock_calls) == 2
        assert len(self.alpr_events) == 5
        assert state.attributes.get('vehicles') == 1
        assert state.state == 'H786P0J'

        event_data = [event.data for event in self.alpr_events if
                      event.data.get('plate') == 'H786P0J']
        assert len(event_data) == 1
        assert event_data[0]['plate'] == 'H786P0J'
        assert event_data[0]['confidence'] == float(90.436699)
        assert event_data[0]['entity_id'] == \
            'image_processing.test_local'
    def test_setup(self, mock_req):
        """Test for operational tube_state sensor with proper attributes."""
        mock_req.get(URL, text=load_fixture('london_underground.json'))
        assert setup_component(self.hass, 'sensor', {'sensor': self.config})

        state = self.hass.states.get('sensor.london_overground')
        assert state.state == 'Minor Delays'
        assert state.attributes.get('Description') == 'something'
Example #27
0
    def test_setup_login_failed(self, mock):
        """Test the setup if a bad username or password is given."""
        mock.put('https://api.sleepiq.sleepnumber.com/rest/login',
                 status_code=401,
                 json=load_fixture('sleepiq-login-failed.json'))

        response = sleepiq.setup(self.hass, self.config)
        self.assertFalse(response)
Example #28
0
async def test_fails_because_of_unique_id(hass, aioclient_mock):
    """Test same config twice fails because of unique_id."""
    aioclient_mock.get(URL, text=load_fixture('wunderground-valid.json'))
    aioclient_mock.get(PWS_URL, text=load_fixture('wunderground-valid.json'))

    config = [
        VALID_CONFIG,
        {**VALID_CONFIG, 'entity_namespace': 'hi'},
        VALID_CONFIG_PWS
    ]
    await async_setup_component(hass, 'sensor', {'sensor': config})
    await hass.async_block_till_done()

    states = hass.states.async_all()
    expected = len(VALID_CONFIG['monitored_conditions']) + \
        len(VALID_CONFIG_PWS['monitored_conditions'])
    assert len(states) == expected
Example #29
0
def test_setup_invalid(hass, aioclient_mock):
    """Test that the component is not loaded with invalid config."""
    aioclient_mock.get(INVALID_URL,
                       text=load_fixture('wunderground-error.json'))

    with assert_setup_component(0, 'sensor'):
        yield from async_setup_component(hass, 'sensor',
                                         {'sensor': INVALID_CONFIG})
Example #30
0
 def test_setup(self, mock):
     """Test successful setup."""
     with patch(
         'vultr.Vultr.server_list',
         return_value=json.loads(
             load_fixture('vultr_server_list.json'))):
         response = vultr.setup(self.hass, self.config)
     assert response
Example #31
0
def aeotec_radiator_thermostat_state_fixture():
    """Load the Aeotec Radiator Thermostat node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/aeotec_radiator_thermostat_state.json"))
Example #32
0
def controller_state_fixture():
    """Load the controller state fixture data."""
    return json.loads(load_fixture("zwave_js/controller_state.json"))
Example #33
0
def null_name_check_state_fixture():
    """Load the null name check node state fixture data."""
    return json.loads(load_fixture("zwave_js/null_name_check_state.json"))
Example #34
0
def binary_switch_state_fixture():
    """Load the hank binary switch node state fixture data."""
    return json.loads(load_fixture("zwave_js/hank_binary_switch_state.json"))
Example #35
0
def bulb_6_multi_color_state_fixture():
    """Load the bulb 6 multi-color node state fixture data."""
    return json.loads(load_fixture("zwave_js/bulb_6_multi_color_state.json"))
Example #36
0
def climate_heatit_z_trm2fx_state_fixture():
    """Load the climate HEATIT Z-TRM2fx thermostat node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/climate_heatit_z_trm2fx_state.json"))
Example #37
0
def iblinds_v2_state_fixture():
    """Load the iBlinds v2 node state fixture data."""
    return json.loads(load_fixture("zwave_js/cover_iblinds_v2_state.json"))
Example #38
0
def qubino_shutter_state_fixture():
    """Load the Qubino Shutter node state fixture data."""
    return json.loads(load_fixture("zwave_js/cover_qubino_shutter_state.json"))
Example #39
0
def eaton_rf9640_dimmer_state_fixture():
    """Load the eaton rf9640 dimmer node state fixture data."""
    return json.loads(load_fixture("zwave_js/eaton_rf9640_dimmer_state.json"))
Example #40
0
def vision_security_zl7432_state_fixture():
    """Load the vision security zl7432 switch node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/vision_security_zl7432_state.json"))
Example #41
0
def climate_radio_thermostat_ct101_multiple_temp_units_state_fixture():
    """Load the climate multiple temp units node state fixture data."""
    return json.loads(
        load_fixture(
            "zwave_js/climate_radio_thermostat_ct101_multiple_temp_units_state.json"
        ))
Example #42
0
def aeon_smart_switch_6_state_fixture():
    """Load the AEON Labs (ZW096) Smart Switch 6 node state fixture data."""
    return json.loads(load_fixture("zwave_js/aeon_smart_switch_6_state.json"))
Example #43
0
def nortek_thermostat_state_fixture():
    """Load the nortek thermostat node state fixture data."""
    return json.loads(load_fixture("zwave_js/nortek_thermostat_state.json"))
Example #44
0
def motorized_barrier_cover_state_fixture():
    """Load the motorized barrier cover node state fixture data."""
    return json.loads(load_fixture("zwave_js/cover_zw062_state.json"))
Example #45
0
def climate_heatit_z_trm3_no_value_state_fixture():
    """Load the climate HEATIT Z-TRM3 thermostat node w/no value state fixture data."""
    return json.loads(
        load_fixture("zwave_js/climate_heatit_z_trm3_no_value_state.json"))
Example #46
0
def in_wall_smart_fan_control_state_fixture():
    """Load the fan node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/in_wall_smart_fan_control_state.json"))
Example #47
0
def climate_eurotronic_spirit_z_state_fixture():
    """Load the climate Eurotronic Spirit Z thermostat node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/climate_eurotronic_spirit_z_state.json"))
Example #48
0
def lock_august_asl03_state_fixture():
    """Load the August Pro lock node state fixture data."""
    return json.loads(load_fixture("zwave_js/lock_august_asl03_state.json"))
Example #49
0
def climate_danfoss_lc_13_state_fixture():
    """Load the climate Danfoss (LC-13) electronic radiator thermostat node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/climate_danfoss_lc_13_state.json"))
Example #50
0
def lock_schlage_be469_state_fixture():
    """Load the schlage lock node state fixture data."""
    return json.loads(load_fixture("zwave_js/lock_schlage_be469_state.json"))
Example #51
0
def climate_radio_thermostat_ct100_plus_state_fixture():
    """Load the climate radio thermostat ct100 plus node state fixture data."""
    return json.loads(
        load_fixture(
            "zwave_js/climate_radio_thermostat_ct100_plus_state.json"))
Example #52
0
def inovelli_lzw36_state_fixture():
    """Load the Inovelli LZW36 node state fixture data."""
    return json.loads(load_fixture("zwave_js/inovelli_lzw36_state.json"))
Example #53
0
def ecolink_door_sensor_state_fixture():
    """Load the Ecolink Door/Window Sensor node state fixture data."""
    return json.loads(load_fixture("zwave_js/ecolink_door_sensor_state.json"))
Example #54
0
def window_cover_state_fixture():
    """Load the window cover node state fixture data."""
    return json.loads(load_fixture("zwave_js/chain_actuator_zws12_state.json"))
Example #55
0
def multisensor_6_state_fixture():
    """Load the multisensor 6 node state fixture data."""
    return json.loads(load_fixture("zwave_js/multisensor_6_state.json"))
Example #56
0
def srt321_hrt4_zw_state_fixture():
    """Load the climate HRT4-ZW / SRT321 / SRT322 thermostat node state fixture data."""
    return json.loads(load_fixture("zwave_js/srt321_hrt4_zw_state.json"))
 async def communicate(input=None):
     """Communicate mock."""
     fixture = bytes(load_fixture("alpr_stdout.txt"), "utf-8")
     return (fixture, None)
Example #58
0
def ge_12730_state_fixture():
    """Load the GE 12730 node state fixture data."""
    return json.loads(load_fixture("zwave_js/fan_ge_12730_state.json"))
Example #59
0
def lock_id_lock_as_id150_state_fixture():
    """Load the id lock id-150 lock node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/lock_id_lock_as_id150_state.json"))
Example #60
0
def light_color_null_values_state_fixture():
    """Load the light color null values node state fixture data."""
    return json.loads(
        load_fixture("zwave_js/light_color_null_values_state.json"))