Skip to main content

sdk for duwi third platform

Project description

Installation

First, you need to make sure you have the SDK installed in your environment. You can do this by running:

pip install duwi_smarthome_sdk_dev

To update the SDK or any existing dependencies to their latest versions, execute:

pip install --upgrade duwi_smarthome_sdk_dev

Usage

Authentication

Before you start fetching information or interacting with devices, you need to authenticate and obtain an access token. Start by initializing the login client:

from duwi_smarthome_sdk_dev import AccountClient

cc = AccountClient(
    app_key="your_app_key",
    app_secret="your_app_secret",
    app_version="0.0.1",
    client_version="0.0.1",
    client_model="homeassistant",
)

res = await cc.login(phone="your_phone_number", password="your_password")

Once logged in, you will receive an access token. This token will be used in subsequent requests to authenticate and authorize your interactions.

Fetching House Information

With the access token, you can now fetch house information or any other data provided by the SDK. Initialize the house info client with your credentials and access token:

from duwi_smarthome_sdk_dev import HouseInfoClient

cc = HouseInfoClient(
    app_key="your_app_key",
    app_secret="your_app_secret",
    access_token="your_access_token",
    app_version="0.0.1",
    client_version="0.0.1",
    client_model="homeassistant",
)

res = await cc.fetch_house_info()

WebSocket Device Synchronization

For real-time device synchronization, set up the WebSocket (WS) client with the necessary credentials. You will also need to define a callback function that handles incoming messages.

Setting up the WebSocket Client

from duwi_smarthome_sdk_dev import DeviceSynchronizationWS
import logging

_LOGGER = logging.getLogger(__name__)

# Define your callback function
async def on_callback(message: str):
    _LOGGER.info(f"on_callback: {message}")

# Initialize the WS client with your credentials
ws = DeviceSynchronizationWS(
    on_callback=on_callback,
    app_key="your_app_key",
    app_secret="your_app_secret",
    access_token="your_access_token",
    refresh_token="your_refresh_token",
    house_no="your_house_no",
    app_version="0.0.1",
    client_version="0.0.1",
    client_model="homeassistant",
)

_LOGGER.warning('Connecting to WS server...')
await ws.reconnect()
await ws.listen()
await ws.keep_alive()

This will establish a connection to the WebSocket server, listen for messages, and handle them using the provided callback function.

Conclusion

By following these steps, you should have a functional setup allowing you to authenticate, fetch data, and synchronize devices in real-time using the duwi_smarthome_sdk_dev. This guide should serve as a starting point for integrating your smart home devices with Home Assistant using the SDK.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

duwi_smarthome_sdk-0.2.2.tar.gz (13.5 kB view details)

Uploaded Source

File details

Details for the file duwi_smarthome_sdk-0.2.2.tar.gz.

File metadata

  • Download URL: duwi_smarthome_sdk-0.2.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for duwi_smarthome_sdk-0.2.2.tar.gz
Algorithm Hash digest
SHA256 60fa8d4e6df4253710f55a2d73608f6bf0691e38f367276e95ec64c78e983f83
MD5 f8f4fe4d3990c4dc2a115b27cbec5777
BLAKE2b-256 d6387ac4f02fe502140b92581c5d0e65679c073b52f66523b7fd4279c0c59b7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page