persandstrom / python-verisure

A python module for reading and changing status of verisure devices through verisure app api.
MIT License
138 stars 42 forks source link

How to get specific data #162

Closed TheLion closed 1 year ago

TheLion commented 1 year ago

Hi,

I'm rewriting my Python script to work with the new API, but I can't figure out how to get a single value, like, for example, the state of a door/window.

I manage to output the complete doorWindows status, but I only need a single one and only the status.

With the old API/version I used

overview['doorWindow']['doorWindowDevice'][0]['state']

But that doesn't work anymore.

Can anyone point me in the right direction?

persandstrom commented 1 year ago

the result will be in a dict where you have to find the device you are looking for. I guess what you get stuck on is that there is a list of devices under ["data"]["installation"]["doorWindows"] You need to iterate through this list in order to find the device.

Something like this:

for door_window in result["data"]["installation"]["doorWindows"]:
   if door_window["device"]["deviceLabel"] == "XXXX XXXX":
      return doow_window["state"]

(written on free hand, but I hope you get the point)

TheLion commented 1 year ago

Thanks! That works like a charm!