-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add a minimal hello world example
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"driver_id": "hello_integration", | ||
"version": "0.0.1", | ||
"min_core_api": "0.20.0", | ||
"name": { "en": "Hello Python integration" }, | ||
"icon": "uc:integration", | ||
"description": { | ||
"en": "Minimal Python integration driver example." | ||
}, | ||
"port": 9080, | ||
"developer": { | ||
"name": "Unfolded Circle ApS", | ||
"email": "[email protected]", | ||
"url": "https://www.unfoldedcircle.com" | ||
}, | ||
"home_page": "https://www.unfoldedcircle.com", | ||
"release_date": "2023-10-30" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
"""Hello world integration example. Bare minimum of an integration driver.""" | ||
import asyncio | ||
import logging | ||
from typing import Any | ||
|
||
import ucapi | ||
|
||
loop = asyncio.get_event_loop() | ||
api = ucapi.IntegrationAPI(loop) | ||
|
||
|
||
async def cmd_handler(entity: ucapi.Button, cmd_id: str, _params: dict[str, Any] | None) -> ucapi.StatusCodes: | ||
""" | ||
Push button command handler. | ||
Called by the integration-API if a command is sent to a configured button-entity. | ||
:param entity: button entity | ||
:param cmd_id: command | ||
:param _params: optional command parameters | ||
:return: status of the command | ||
""" | ||
print(f"Got {entity.id} command request: {cmd_id}") | ||
|
||
return ucapi.StatusCodes.OK | ||
|
||
|
||
if __name__ == "__main__": | ||
logging.basicConfig() | ||
|
||
button = ucapi.Button( | ||
"button1", | ||
"Push the button", | ||
cmd_handler=cmd_handler, | ||
) | ||
api.available_entities.add(button) | ||
|
||
# We are ready all the time! Otherwise, use @api.listens_to(ucapi.Events.CONNECT) & DISCONNECT | ||
api.set_device_state(ucapi.DeviceStates.CONNECTED) | ||
|
||
loop.run_until_complete(api.init("hello_integration.json")) | ||
loop.run_forever() |