Package: aioremootio
aioremootio - An asynchronous API client library for Remootioaioremootiois an asynchronous API client library forRemootiowritten in Python 3 and
based onasyncioandaiohttp.Supported functionalities of the deviceWith this client library is currently possible to listen to state changes of aRemootiodevice,
to listen to some events triggered by it, furthermore to operate the gate or garage door connected to it.This client library supports currently the listening to following kind of events triggered by the device:STATE_CHANGEwhich is triggered by the device when its state changesRELAY_TRIGGERwhich is triggered by the device when its control output has been triggered to operate the
connected gate or garage doorLEFT_OPENwhich is triggered by the device when the connected gate or garage door has been left openRESTARTwhich is triggered by the device when it was restartedUsing the libraryThe following example demonstrates how you can use this library.fromtypingimportNoReturnimportloggingimportasyncioimportaiohttpimportaioremootioclassExampleStateListener(aioremootio.Listener[aioremootio.StateChange]):__logger:logging.Loggerdef__init__(self,logger:logging.Logger):self.__logger=loggerasyncdefexecute(self,client:aioremootio.RemootioClient,subject:aioremootio.StateChange)->NoReturn:self.__logger.info("State of the device has been changed. Host [%s] OldState [%s] NewState [%s]"%(client.host,subject.old_state,subject.new_state))asyncdefmain()->NoReturn:logger=logging.getLogger(__name__)logger.setLevel(logging.INFO)handler:logging.Handler=logging.StreamHandler()handler.setFormatter(logging.Formatter(fmt="%(asctime)s[%(levelname)s]%(message)s"))logger.addHandler(handler)connection_options:aioremootio.ConnectionOptions=\aioremootio.ConnectionOptions("192.168.0.1","API_SECRET_KEY","API_AUTH_KEY")state_change_listener:aioremootio.Listener[aioremootio.StateChange]=ExampleStateListener(logger)remootio_client:aioremootio.RemootioClientasyncwithaiohttp.ClientSession()asclient_session:try:remootio_client=awaitaioremootio.RemootioClient(connection_options,client_session,aioremootio.LoggerConfiguration(logger=logger),[state_change_listener])exceptaioremootio.RemootioClientConnectionEstablishmentError:logger.exception("The client has failed to establish connection to the Remootio device.")exceptaioremootio.RemootioClientAuthenticationError:logger.exception("The client has failed to authenticate with the Remootio device.")exceptaioremootio.RemootioError:logger.exception("Failed to create client because of an error.")else:logger.info("State of the device:%s",remootio_client.state)ifremootio_client.state==aioremootio.State.NO_SENSOR_INSTALLED:awaitremootio_client.trigger()else:awaitremootio_client.trigger_open()awaitremootio_client.trigger_close()whileTrue:awaitasyncio.sleep(0.1)if__name__=="__main__":try:asyncio.run(main())exceptKeyboardInterrupt:passTo get theAPI Secret KeyandAPI Auth Keyof yourRemootiodevice you must enable the
API on it according to theRemootio Websocket API documentation.Running the bundled examplesTheproject sourcedoes also contain two examples.The exampleexample.pydemonstrates how you can
use the client as a Python object.The exampleexample_mc.pydemonstrates how you can
use the client as a Python object where it does not establish a connection to the Remootio device automatically
during its initialization.The exampleexample_acm.pydemonstrates how
you can use the client as an asynchronous context manager.To run the bundled examples you mustalso enable the API on yourRemootiodevice to get theAPI Secret KeyandAPI Auth
Keyof it, andadd the source folder/srcof the repository to yourPYTHONPATH.After the two steps described above you can run the bundled examples with the argument--helpto show
the usage information. E.g.:python example.py --helpRunning the bundled testsTo run the bundled tests you must create the.\remootio_device.configuration.jsonfile with a content according
to the following template.{
    "host": "IP-ADDRESS-OR-HOST-NAME-OF-YOUR-DEVICE",
    "api_secret_key": "API-SECRET-KEY-OF-YOUR-DEVICE",
    "api_auth_key": "API-AUTH-KEY-OF-YOUR-DEVICE",
    "api_version": API-VERSION-OF-YOUR-DEVICE
}Copyright © 2021 Gergö Gabor Ilyes-Veisz.
Licensed under theApache License, Version 2.0