How to use the pysmartthings.entity.Entity 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 / pysmartthings / app.py View on Github external
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):
        """Save changes to the app OAuth Client settings."""
        response = await self._api.update_app_oauth(self._app_id, self.to_data())
        if response:
            self.apply_data(response)


class AppEntity(Entity, App):
    """Define a SmartThings App entity."""

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

    async def refresh(self):
        """Refresh the app information using the API."""
        data = await self._api.get_app(self._app_id)
        self.apply_data(data)

    async def save(self):
        """Save the changes made to the app."""
github andrewsayre / pysmartthings / pysmartthings / app.py View on Github external
def app_id(self):
        """Get the associated app id."""
        return self._app_id

    @property
    def settings(self) -> dict:
        """Get the settings for the app."""
        return self._settings

    @settings.setter
    def settings(self, value: dict):
        """Set the settings for the app."""
        self._settings = value


class AppSettingsEntity(Entity, AppSettings):
    """Define a SmartThings App settings entity."""

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

    async def refresh(self):
        """Refresh the value of the entity."""
        if not self._app_id:
            raise ValueError("Cannot refresh without an app_id")
        data = await self._api.get_app_settings(self._app_id)
        self.apply_data(data)
github andrewsayre / pysmartthings / pysmartthings / device.py View on Github external
def __init__(
        self, api: Api, data: Optional[dict] = None, device_id: Optional[str] = None
    ):
        """Create a new instance of the DeviceEntity class."""
        Entity.__init__(self, api)
        Device.__init__(self)
        if data:
            self.apply_data(data)
        if device_id:
            self._device_id = device_id
        self._status = DeviceStatus(api, self._device_id)
github andrewsayre / pysmartthings / pysmartthings / scene.py View on Github external
def location_id(self) -> str:
        """Get the location this scene is in."""
        return self._location_id

    @property
    def name(self) -> str:
        """Get the name of the scene."""
        return self._name

    @property
    def scene_id(self) -> str:
        """Get the id of the scene."""
        return self._scene_id


class SceneEntity(Entity, Scene):
    """Define a scene entity."""

    def __init__(self, api: Api, data: Optional[Dict] = None):
        """Create a new instance of the class."""
        Entity.__init__(self, api)
        Scene.__init__(self)
        if data:
            self.apply_data(data)

    async def execute(self):
        """Execute the scene."""
        result = await self._api.execute_scene(self._scene_id)
        return result == {"status": "success"}

    async def refresh(self):
        """Refresh is not implemented."""
github andrewsayre / pysmartthings / pysmartthings / installedapp.py View on Github external
def created_date(self) -> str:
        """Get the date the installed app was created."""
        return self._created_date

    @property
    def last_updated_date(self) -> str:
        """Get the date the installed app was updated."""
        return self._last_updated_date

    @property
    def classifications(self) -> Sequence[str]:
        """Get the collection of classifications."""
        return self._classifications


class InstalledAppEntity(Entity, InstalledApp):
    """Define the InstalledAppEntity class."""

    def __init__(self, api: Api, data=None, installed_app_id=None):
        """Create a new instance of the InstalledAppEntity class."""
        Entity.__init__(self, api)
        InstalledApp.__init__(self)
        if data:
            self.apply_data(data)
        if installed_app_id:
            self._installed_app_id = installed_app_id

    async def refresh(self):
        """Refresh the installedapp information using the API."""
        data = await self._api.get_installed_app(self._installed_app_id)
        self.apply_data(data)
github andrewsayre / pysmartthings / pysmartthings / device.py View on Github external
"""Get the device id."""
        return self._device_id

    @device_id.setter
    def device_id(self, value: str):
        """Set the device id."""
        self._device_id = value

    async def refresh(self):
        """Refresh the values of the entity."""
        data = await self._api.get_device_status(self.device_id)
        if data:
            self.apply_data(data)


class DeviceEntity(Entity, Device):
    """Define a device entity."""

    def __init__(
        self, api: Api, data: Optional[dict] = None, device_id: Optional[str] = None
    ):
        """Create a new instance of the DeviceEntity class."""
        Entity.__init__(self, api)
        Device.__init__(self)
        if data:
            self.apply_data(data)
        if device_id:
            self._device_id = device_id
        self._status = DeviceStatus(api, self._device_id)

    async def refresh(self):
        """Refresh the device information using the API."""
github andrewsayre / pysmartthings / pysmartthings / location.py View on Github external
def locale(self) -> str:
        """Get the IETF BCP 47 language tag of the location."""
        return self._locale

    @property
    def country_code(self) -> str:
        """Get the country code of the location."""
        return self._country_code

    @property
    def timezone_id(self) -> str:
        """Get the ID matching the Java Time Zone ID of the location."""
        return self._timezone_id


class LocationEntity(Entity, Location):
    """Define a location entity."""

    def __init__(
        self, api: Api, data: Optional[dict] = None, location_id: Optional[str] = None
    ):
        """Create a new instance of the LocationEntity."""
        Entity.__init__(self, api)
        Location.__init__(self)
        if data:
            self.apply_data(data)
        if location_id:
            self._location_id = location_id

    async def refresh(self):
        """Refresh the location information."""
        data = await self._api.get_location(self._location_id)