Skip to content

Commit 17e501d

Browse files
committed
Adds the source field to allow xiaomi.fan.p76 to function over generic miot.
Also defaults the value to the first value when unable to find the choice
1 parent 0aa4df3 commit 17e501d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

miio/miot_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class MiotProperty(MiotBaseModel):
228228
choices: Optional[list[MiotEnumValue]] = Field(alias="value-list")
229229
gatt_access: Optional[list[Any]] = Field(alias="gatt-access")
230230

231+
source: Optional[int] = None
232+
231233
# TODO: currently just used to pass the data for miiocli
232234
# there must be a better way to do this..
233235
value: Optional[Any] = None
@@ -238,7 +240,10 @@ def pretty_value(self):
238240

239241
if self.choices is not None:
240242
# TODO: find a nicer way to get the choice by value
241-
selected = next(c.description for c in self.choices if c.value == value)
243+
selected = next(
244+
(c.description for c in self.choices if c.value == value),
245+
self.choices[0],
246+
)
242247
current = f"{selected} (value: {value})"
243248
return current
244249

0 commit comments

Comments
 (0)