Requests
The pyenphase package can be used to send any request to the Envoy. Either to obtain data from endpoints not already collected, or send PUT or POST requests to the Envoy. Access to the used endpoints is enabled by the Authorization level set during authentication. The request response is returned to the caller and not stored in the Envoy data model.
envoy = Envoy(host_ip_or_name)
await envoy.setup()
await envoy.authenticate(username=username, password=password, token=token)
myresponse: aiohttp.ClientResponse = await envoy.request('/my/own/endpoint')
status_code = myresponse.status
myjson_data = await myresponse.json()
await envoy.close()
You can run the package using Envoy.request() only (without calling probe and update), which provides an API into the Envoy without using the internally pre-configured data collections.
ClientResponse
Envoy.request() returns an aiohttp.ClientResponse as the result. [1]
To access the response data, use aiohttp.ClientResponse.read() for the raw bytes, aiohttp.ClientResponse.text() for a decoded str, or aiohttp.ClientResponse.json() for a parsed JSON object.
Note that ClientResponse.json() uses Python’s standard decoder json.loads by default. To use a different decoder, pass it via the loads= parameter, for example:
import orjson
myjson_data = await myresponse.json(loads=orjson.loads)