Ejemplo n.º 1
0
def test_cloud_init():
    """Test that the dev or prod url are being set correctly."""
    api_dev = hound.cloud(MOCK_API_KEY)
    assert api_dev._url_detections == URL_DETECTIONS_DEV

    api_prod = hound.cloud(MOCK_API_KEY, mode="prod")
    assert api_prod._url_detections == URL_DETECTIONS_PROD

    with pytest.raises(hound.SimplehoundException) as exc:
        hound.cloud(MOCK_API_KEY, mode="bad")
    assert str(exc.value) == "Mode bad is not allowed, must be dev or prod"
Ejemplo n.º 2
0
 def __init__(
     self,
     api_key,
     account_type,
     save_file_folder,
     save_timestamped_file,
     camera_entity,
     name,
 ):
     """Init."""
     super().__init__()
     self._api = hound.cloud(api_key, account_type)
     self._camera = camera_entity
     if name:
         self._name = name
     else:
         self._camera_name = split_entity_id(camera_entity)[1]
         self._name = "sighthound_{}".format(self._camera_name)
     self._state = None
     self.faces = []
     self.people = []
     self._state = None
     self._last_detection = None
     self._image_width = None
     self._image_height = None
     if save_file_folder:
         self._save_file_folder = save_file_folder
     self._save_timestamped_file = save_timestamped_file
Ejemplo n.º 3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the platform."""
    # Validate credentials by processing image.
    api_key = config[CONF_API_KEY]
    account_type = config[CONF_ACCOUNT_TYPE]
    api = hound.cloud(api_key, account_type)
    try:
        api.detect(b"Test")
    except hound.SimplehoundException as exc:
        _LOGGER.error("Sighthound error %s setup aborted", exc)
        return

    save_file_folder = config.get(CONF_SAVE_FILE_FOLDER)
    if save_file_folder:
        save_file_folder = Path(save_file_folder)

    entities = []
    for camera in config[CONF_SOURCE]:
        sighthound = SighthoundEntity(
            api,
            camera[CONF_ENTITY_ID],
            camera.get(CONF_NAME),
            save_file_folder,
            config[CONF_SAVE_TIMESTAMPTED_FILE],
        )
        entities.append(sighthound)
    add_entities(entities)
Ejemplo n.º 4
0
def test_cloud_detect_good():
    with requests_mock.Mocker() as mock_req:
        mock_req.post(URL_DETECTIONS_DEV,
                      status_code=hound.HTTP_OK,
                      json=DETECTIONS)
        api = hound.cloud(MOCK_API_KEY)
        detections = api.detect(MOCK_BYTES)
        assert detections == DETECTIONS
Ejemplo n.º 5
0
def test_cloud_detect_bad_key():
    with pytest.raises(hound.SimplehoundException
                       ) as exc, requests_mock.Mocker() as mock_req:
        mock_req.post(URL_DETECTIONS_DEV,
                      status_code=hound.BAD_API_KEY,
                      json=DETECTIONS)
        api = hound.cloud(MOCK_API_KEY)
        detections = api.detect(MOCK_BYTES)
    assert str(exc.value) == "Bad API key for Sighthound"
Ejemplo n.º 6
0
def test_cloud_recognize_licenseplate_good():
    with requests_mock.Mocker() as mock_req:
        mock_req.post(
            URL_RECOGNITIONS_DEV + "licenseplate",
            status_code=hound.HTTP_OK,
            json=RECOGNITIONS_LICENSEPLATE,
        )
        api = hound.cloud(MOCK_API_KEY)
        recognitions = api.recognize(MOCK_BYTES, "licenseplate")
        assert recognitions == RECOGNITIONS_LICENSEPLATE
Ejemplo n.º 7
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the platform."""
    # Validate credentials by processing image.
    api_key = config[CONF_API_KEY]
    account_type = config[CONF_ACCOUNT_TYPE]
    api = hound.cloud(api_key, account_type)
    try:
        api.detect(b"Test")
    except hound.SimplehoundException as exc:
        _LOGGER.error("Sighthound error %s setup aborted", exc)
        return

    if save_file_folder := config.get(CONF_SAVE_FILE_FOLDER):
        save_file_folder = Path(save_file_folder)