starkillerOG / motion-blinds

Python library for interfacing with Motion Blinds
MIT License
22 stars 9 forks source link

Return attributes of gateway and blinds as dictionaries #6

Closed budachst closed 3 years ago

budachst commented 3 years ago

It would be much easier to make use of the returned attributes, if they could be accessed as dictinaries, instead of a (oddly) formatted string, especially with those brackes at either ends. Also, if you would consider to return the attributes as dictionaries, the battery voltage should be a named entity.

starkillerOG commented 3 years ago

I think what you are refering to is the representation of a blind class, that schould always be a string. You can acces all attributes/properties of a blind which will give you the python type of that variable like int or double. I could make an extra propertie that gives you all the properties in one dict if you like, but that is normaly not needed when you can acces all individual properties.

Could you specify the code you are using that gives you the "oddly formatted string", and specifically which properties you would like to have form that string? I could then give you an example of how to properly acces those attributes/properties

budachst commented 3 years ago

Yeah… you're right. I shouldn't be so lazy… ;) I thought to save some code, but I can of course easily create my own objects and update the properties for them. I was only tempted by the output of your examples and though, that those were already dicts.

However, what I still don't get is what is needed to reference a blind. I thought, that only the blinds mac would be needed, but when I look at the examples, I wonder how it is really working…

So, I would need to define each blind as a single object:

>>> rollerBlind = list(m.device_list.values())[0]
>>> rollerBlind.position
0
>>> rollerBlind.battery_voltage
12.01
>>> print (rollerBlind)
<MotionBlind mac: 10521ca658240001, type: RollerBlind, status: Stopped, position: 0 %, angle: 0.0, limit: Limits, battery: 73.0 %, 12.01 V, RSSI: -54 dBm>

However, when dealing with multiple objects, it still would be nice to have a single dict (of dicts) with every blind in it. As I said, I can do this of course by myself.

starkillerOG commented 3 years ago

To get the dict containing all blinds use:

>>> print(m.device_list)

The keys are the mac's of the blinds, the values are the blind objects. If you want to get it as a list use:

>>> print(m.device_list.values())
budachst commented 3 years ago

Yeah - thanks, that will do it nicely.