Closed Taraman17 closed 1 year ago
Thanks for the detailed explanation.
So from my point of view HomeAttribute
(or really any thing in model.py
) is only a convenience wrapper around the data returned by the API. It is really just used to "strong type" the data so that it is easier to work with (intelisense etc.).
Which is why I would personally go with your Option 2. I would add a new class HomeeAttributeOptions
that strong types all the options and return it from HomeeAttribute
:
@property
def options(self) -> HomeeAttributeOptions:
return HomeeAttributeOptions(self._data['options'])
or just assign self.options
in __init__
.
If an option is missing users could still access them via the raw data.
Thank you for the quick reply.
Most interestingly the last part is exaclty my approach - this is how it looks like in my draft:
@property
def options(self) -> HomeeAttributeOptions:
"""The options collection of the attribute. Optional, not on every attribute."""
return HomeeAttributeOptions(self._data["options"])
;-)
An Attribute in Homee can have options. The currently known are:
At least the last one is useful for other applications acessing Homee. So it is desired to expose them in pymee.
There are two possible approaches:
Option 1
Iterate over the options and convert the dict to an object:
Option 2
Add getters for the known possible options and return empty values if they don't exist.
@FreshlyBrewedCode: Since it is your project, I want to get your opinion on which approach to use before I do a pull request
Example code of an Attribute with options: