#!/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 async def cmd_handler_mp( entity: ucapi.MediaPlayer, cmd_id: str, _params: dict[str, Any] | None ) -> ucapi.StatusCodes: print(f"Got {entity.id} command request: {cmd_id}") return ucapi.StatusCodes.OK @api.listens_to(ucapi.Events.CONNECT) async def on_connect() -> None: # When the remote connects, we just set the device state. We are ready all the time! await api.set_device_state(ucapi.DeviceStates.CONNECTED) if __name__ == "__main__": logging.basicConfig() button = ucapi.Button( "button1", "Push the button", cmd_handler=cmd_handler, ) api.available_entities.add(button) media_player = ucapi.MediaPlayer(identifier="test1", name="Test", features=[ucapi.media_player.Features.ON_OFF, ucapi.media_player.Features.TOGGLE, ucapi.media_player.Features.VOLUME, ucapi.media_player.Features.DPAD, ucapi.media_player.Features.COLOR_BUTTONS, ucapi.media_player.Features.SELECT_SOURCE, ucapi.media_player.Features.SELECT_SOUND_MODE], attributes={ucapi.media_player.Attributes.SOURCE_LIST: ["foo", "bar"], ucapi.media_player.Attributes.SOUND_MODE_LIST: ["1", "2", "3"]}, device_class=ucapi.media_player.DeviceClasses.RECEIVER, cmd_handler=cmd_handler_mp) api.available_entities.add(media_player) loop.run_until_complete(api.init("hello_integration.json")) loop.run_forever()