Exemplo n.º 1
0
    def led_rgb(self, color):
        """Set devices LED color."""
        if (not isinstance(color, (list, tuple))
                or not all(isinstance(item, int) for item in color)):
            raise SkybellException(ERROR.COLOR_VALUE_NOT_VALID, color)

        self._set_setting({
            CONST.SETTINGS_LED_R: color[0],
            CONST.SETTINGS_LED_G: color[1],
            CONST.SETTINGS_LED_B: color[2]
        })
Exemplo n.º 2
0
    def motion_sensor(self, enabled):
        """Set the motion sensor state."""
        if enabled is True:
            value = CONST.SETTINGS_MOTION_POLICY_ON
        elif enabled is False:
            value = CONST.SETTINGS_MOTION_POLICY_OFF
        else:
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (CONST.SETTINGS_MOTION_POLICY, enabled))

        self._set_setting({CONST.SETTINGS_MOTION_POLICY: value})
Exemplo n.º 3
0
def _validate_setting(setting, value):
    """Validate the setting and value."""
    if setting not in CONST.ALL_SETTINGS:
        raise SkybellException(ERROR.INVALID_SETTING, setting)

    if setting == CONST.SETTINGS_DO_NOT_DISTURB:
        if value not in CONST.SETTINGS_DO_NOT_DISTURB_VALUES:
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))

    if setting == CONST.SETTINGS_OUTDOOR_CHIME:
        if value not in CONST.SETTINGS_OUTDOOR_CHIME_VALUES:
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))

    if setting == CONST.SETTINGS_MOTION_POLICY:
        if value not in CONST.SETTINGS_MOTION_POLICY_VALUES:
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))

    if setting == CONST.SETTINGS_MOTION_THRESHOLD:
        if value not in CONST.SETTINGS_MOTION_THRESHOLD_VALUES:
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))

    if setting == CONST.SETTINGS_VIDEO_PROFILE:
        if value not in CONST.SETTINGS_VIDEO_PROFILE_VALUES:
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))

    if setting in CONST.SETTINGS_LED_COLOR:
        if (value < CONST.SETTINGS_LED_VALUES[0]
                or value > CONST.SETTINGS_LED_VALUES[1]):
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))

    if setting == CONST.SETTINGS_LED_INTENSITY:
        if not isinstance(value, int):
            raise SkybellException(ERROR.COLOR_INTENSITY_NOT_VALID, value)

        if (value < CONST.SETTINGS_LED_INTENSITY_VALUES[0]
                or value > CONST.SETTINGS_LED_INTENSITY_VALUES[1]):
            raise SkybellException(ERROR.INVALID_SETTING_VALUE,
                                   (setting, value))
Exemplo n.º 4
0
    def send_request(self,
                     method,
                     url,
                     headers=None,
                     json_data=None,
                     retry=True):
        """Send requests to Skybell."""
        if not self.cache(CONST.ACCESS_TOKEN) and url != CONST.LOGIN_URL:
            self.login()

        if not headers:
            headers = {}

        if self.cache(CONST.ACCESS_TOKEN):
            headers['Authorization'] = 'Bearer ' + \
                self.cache(CONST.ACCESS_TOKEN)

        headers['user-agent'] = (
            'SkyBell/3.4.1 (iPhone9,2; iOS 11.0; loc=en_US; lang=en-US) '
            'com.skybell.doorbell/1')
        headers['content-type'] = 'application/json'
        headers['accepts'] = '*/*'
        headers['x-skybell-app-id'] = self.cache(CONST.APP_ID)
        headers['x-skybell-client-id'] = self.cache(CONST.CLIENT_ID)

        _LOGGER.debug("HTTP %s %s Request with headers: %s", method, url,
                      headers)

        try:
            response = getattr(self._session, method)(url,
                                                      headers=headers,
                                                      json=json_data)
            _LOGGER.debug("%s %s", response, response.text)

            if response and response.status_code < 400:
                return response
        except RequestException as exc:
            _LOGGER.warning("Skybell request exception: %s", exc)

        if retry:
            self.login()

            return self.send_request(method, url, headers, json_data, False)

        raise SkybellException(ERROR.REQUEST, "Retry failed")