python api client for digitalSTROM
Project description
pydigitalstrom
Run bundled docker
$ docker-compose build
$ docker-compose up -d
$ docker-compose exec python bash
Run the tests locally
$ docker-compose run --rm python tox
VSCode
pydigitalstrom supports VSCode devcontainers for code completion and test runner
Concept
Since digitalSTROM is mainly build on the concept of scenes, this library also only support setting scenes.
Currently user defined named scenes and generic scenes are supported.
Example usage
import asyncio
from pydigitalstrom.apptokenhandler import DSAppTokenHandler
from pydigitalstrom.client import DSClient
async def test():
# get activated app token
apptokenhandler = DSAppTokenHandler(
host="https://dss.local:8080",
username="dssadmin",
password="mySuperSecretPassword",
)
apptoken = await apptokenhandler.request_apptoken()
# connect the client and initialize the scenes cache
client = DSClient(
host="https://dss.local:8080", apptoken=apptoken, apartment_name="Apartment"
)
await client.initialize()
# list and turn on all scenes
scenes = client.get_scenes()
for scene in scenes.values():
print(scene.unique_id)
print(scene.name)
# await scene.turn_on()
loop = asyncio.get_event_loop()
loop.run_until_complete(test())
Event listener
Run an event listener to get scene call updates from digitalSTROM
import asyncio
from pydigitalstrom.apptokenhandler import DSAppTokenHandler
from pydigitalstrom.client import DSClient
from pydigitalstrom.listener import DSEventListener
async def callback(event):
print("callback called")
print(event)
# disable certificate warnings - dss uses self signed
async def test(loop):
# get activated app token
apptokenhandler = DSAppTokenHandler(
host="https://dss.local:8080",
username="dssadmin",
password="mySuperSecretPassword",
)
apptoken = await apptokenhandler.request_apptoken()
# connect listener and print all events coming in
client = DSClient(
host="https://dss.local:8080", apptoken=apptoken, apartment_name="Apartment"
)
listener = DSEventListener(
client=client, event_id=1, event_name="callScene", timeout=1, loop=loop
)
await listener.start()
listener.register(callback=callback)
while True:
await asyncio.sleep(1)
loop = asyncio.get_event_loop()
loop.run_until_complete(test(loop=loop))
Making a new release
bumpversion is used to manage releases.
Add your changes to the CHANGELOG, run
docker-compose run --rm python bumpversion <major|minor|patch>
then push (including tags).
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
[1.4.0] - 2020-02-10
Changed
- BREAKING allow passing in an asyncio loop instead of an aiohttp session
[1.3.1] - 2020-01-27
Changed
- Check when to override session cookies
[1.3.0] - 2020-01-27
Changed
- Update aiohttp dependency, remove urllib3 dependency
- Update test dependencies
- BREAKING only support and test against the latest HomeAssistant Docker Python version, which is currently 3.7.6
- Allow to pass in aiohttp session
[0.6.1] - 2019-09-01
Changed
- change the way ssl certificate validation is disabled
[0.6.0] - 2019-09-01
Changed
- BREAKING - app token will not be stored in a file anymore
- BREAKING - DSClient splitted into multiple classes, app token retrieval standalone
- updated python versions and dependencies
- format source code using black
[0.5.0] - 2019-02-09
Changed
- BREAKING - changed device unique_id to be underscore separated instead of dot separated
- updated python versions and dependencies
[0.4.1] - 2018-10-01
Changed
- Registering callbacks on the DSEventListener should not be async
[0.4.0] - 2018-10-01
Changed
- BREAKING - this library will only support scenes from now on since device actions suck on digitalSTROM!
- BREAKING - the DSEventListener will now forward event data to the callback instead of updating states on it's own
[0.3.4] - 2018-09-30
Added
- Update AreaBlind state from DSListener
[0.3.3] - 2018-09-29
Added
- Support for AreaBlind, basically converted scenes 0-9 to proper blind devices for the area
[0.3.2] - 2018-09-16
Changed
- Allow passing an asyncio loop to the DSListener
[0.3.1] - 2018-09-16
Added
- Support update callbacks on AreaLight
[0.3.0] - 2018-09-16
Added
- Support for AreaLight, basically converted scenes 0-9 to proper light devices for the area
- Event listener that can update the AreaLight status
Changed
- BREAKING - devices etc are now initialized by DSClient.initialize() and DSClient getter functions are not async anymore
[0.2.0] - 2018-09-11
Added
- Test coverage increased
Changed
- BREAKING - All things async
- Use aiohttp to make calls and provide api-using functions as async
- Comply with PEP8 formatting rules
- BREAKING merged DSTerminal and DSDevice into DSDevice
- BREAKING minimum required Python version is now 3.5.3
- Multi version Docker environment to run full tox suite
[0.1.2] - 2018-09-10
Fixed
- Some API calls should not expect a result node in response
Changed
- Added more gitignores for docker env and app config
[0.1.1] - 2018-09-10
Added
- Tests for blind, light, meter and scene
- Add move_up, move_down and stop to blind
Changed
- DSDevice and DSTerminal signature of request now allows for responses without result node
[0.1.0] - 2018-09-09
Changed
- Complete rewrite
Added
- (yellow) Support for GE-KL200, GE-KM200
- (grey) Support for GR-KL200
- (black) Support for SW-ZW200-F, SW-TKM200
- (meter) Support for dSM12
- (server) Support for dSS IP
- Support for scenes
[0.0.1] - 2016-11-23
Added
- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pydigitalstrom-1.4.0.tar.gz
.
File metadata
- Download URL: pydigitalstrom-1.4.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdc95a1e3cb96b11561dd712d4b0720b04366042055f496646dedf247ec944d2 |
|
MD5 | 3d60e96dc930efd179ba0c92f84d434e |
|
BLAKE2b-256 | dcc2605dcfb52f367d94c680961df6d40397f8456c9ce77e255c36d2b2535246 |