Skip to content

Commit

Permalink
Allow passing choices as dict
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Mar 18, 2024
1 parent b1f6cd6 commit 328fc72
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion miio/descriptorcollection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from collections import UserDict
from enum import Enum
from inspect import getmembers
from typing import TYPE_CHECKING, Generic, TypeVar, cast

Expand Down Expand Up @@ -121,7 +122,11 @@ def _handle_constraints(self, prop: PropertyDescriptor) -> None:
retrieve_choices_function = getattr(
self._device, prop.choices_attribute
)
prop.choices = retrieve_choices_function()
choices = retrieve_choices_function()
if isinstance(choices, dict):
prop.choices = Enum(f"GENERATED_ENUM_{prop.name}", choices)
else:
prop.choices = choices

if prop.choices is None:
raise ValueError(
Expand Down

0 comments on commit 328fc72

Please sign in to comment.