How to use the pysmartthings.app.AppOAuth function in pysmartthings

To help you get started, we’ve selected a few pysmartthings examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andrewsayre / pysmartthings / tests / test_app.py View on Github external
def test_init():
        """Tests the initialization."""
        # Arrange
        app_id = '5c03e518-118a-44cb-85ad-7877d0b302e4'
        # Act
        oauth = AppOAuth(app_id)
        # Assert
        assert app_id == oauth.app_id
        assert oauth.scope is not None
github andrewsayre / pysmartthings / tests / test_smartthings.py View on Github external
async def test_update_app_oauth(smartthings):
        """Tests updating OAuth settings."""
        # Arrange
        oauth = AppOAuth(APP_ID)
        oauth.client_name = 'pysmartthings-test'
        oauth.scope.append('r:devices')
        # Act
        oauth_entity = await smartthings.update_app_oauth(oauth)
        # Assert
        assert oauth_entity.app_id == oauth.app_id
        assert oauth_entity.client_name == oauth.client_name
        assert oauth_entity.scope == oauth.scope
github andrewsayre / pysmartthings / tests / test_app.py View on Github external
def test_client_name_invalid():
        """Tests setting an invalid client name."""
        # Arrange
        oauth = AppOAuth('5c03e518-118a-44cb-85ad-7877d0b302e4')
        # Act/Assert
        with pytest.raises(ValueError):
            oauth.client_name = ''
github andrewsayre / pysmartthings / tests / test_smartthings.py View on Github external
async def test_generate_app_oauth(smartthings):
        """Tests generating new OAuth info."""
        # Arrange
        oauth = AppOAuth(APP_ID)
        oauth.client_name = 'pysmartthings'
        oauth.scope.append('r:devices:*')
        # Act
        entity = await smartthings.generate_app_oauth(oauth)
        # Assert
        assert entity.client_id == '0b6a77d4-2dff-4b00-ba33-35f660fbfb83'
        assert entity.client_secret == '05a49aac-55d6-4092-96bf-7ca6ca3666d3'
        assert entity.client_details.app_id == APP_ID
        assert entity.client_details.client_name == 'pysmartthings'
        assert entity.client_details.scope == ['r:devices:$', 'r:devices:*']
github andrewsayre / pysmartthings / tests / test_app.py View on Github external
def test_client_name():
        """Tests get/set of client name."""
        # Arrange
        oauth = AppOAuth('5c03e518-118a-44cb-85ad-7877d0b302e4')
        # Act
        expected = "my_app"
        oauth.client_name = expected
        actual = oauth.client_name
        # Assert
        assert actual == expected
github andrewsayre / pysmartthings / pysmartthings / app.py View on Github external
return self._client_name

    @client_name.setter
    def client_name(self, value: str):
        """Set the name given to the OAuth client."""
        if not value:
            raise ValueError("Value can not be None or an empty string.")
        self._client_name = value

    @property
    def scope(self) -> List[str]:
        """Get the list of SmartThings API OAuth scope identifiers."""
        return self._scope


class AppOAuthEntity(Entity, AppOAuth):
    """Define oauth client settings."""

    def __init__(self, api: Api, app_id: str, data=None):
        """Create a new instance of the OAuth class."""
        Entity.__init__(self, api)
        AppOAuth.__init__(self, app_id)
        if data:
            self.apply_data(data)

    async def refresh(self):
        """Retrieve the latest values from the API."""
        data = await self._api.get_app_oauth(self._app_id)
        if data:
            self.apply_data(data)

    async def save(self):
github andrewsayre / pysmartthings / pysmartthings / app.py View on Github external
def __init__(self, api: Api, app_id: str, data=None):
        """Create a new instance of the OAuth class."""
        Entity.__init__(self, api)
        AppOAuth.__init__(self, app_id)
        if data:
            self.apply_data(data)