Skip to content

Commit

Permalink
Implement choices_attribute for setting decorator (#1587)
Browse files Browse the repository at this point in the history
Split out from #1543
Will be used for Multi Map Enum select.
  • Loading branch information
starkillerOG committed Nov 9, 2022
1 parent 1c3b463 commit b5a2940
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 12 additions & 1 deletion miio/device.py
Expand Up @@ -5,7 +5,12 @@
import click

from .click_common import DeviceGroupMeta, LiteralParamType, command, format_output
from .descriptors import ActionDescriptor, SensorDescriptor, SettingDescriptor
from .descriptors import (
ActionDescriptor,
EnumSettingDescriptor,
SensorDescriptor,
SettingDescriptor,
)
from .deviceinfo import DeviceInfo
from .devicestatus import DeviceStatus
from .exceptions import DeviceInfoUnavailableException, PayloadDecodeException
Expand Down Expand Up @@ -258,6 +263,12 @@ def settings(self) -> Dict[str, SettingDescriptor]:
)

setting.setter = getattr(self, setting.setter_name)
if (
isinstance(setting, EnumSettingDescriptor)
and setting.choices_attribute is not None
):
retrieve_choices_function = getattr(self, setting.choices_attribute)
setting.choices = retrieve_choices_function() # This can do IO

return settings

Expand Down
4 changes: 0 additions & 4 deletions miio/devicestatus.py
Expand Up @@ -219,10 +219,6 @@ def decorator_setting(func):
step=step or 1,
)
elif choices or choices_attribute:
if choices_attribute is not None:
# TODO: adding choices from attribute is a bit more complex, as it requires a way to
# construct enums pointed by the attribute
raise NotImplementedError("choices_attribute is not yet implemented")
descriptor = EnumSettingDescriptor(
**common_values,
choices=choices,
Expand Down

0 comments on commit b5a2940

Please sign in to comment.