Skip to content

Commit ae0b93e

Browse files
fix: roborock enum
1 parent 250d5fc commit ae0b93e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

roborock/code_mappings.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ class RoborockEnum(IntEnum):
1111
"""Roborock Enum for codes with int values"""
1212

1313
@classmethod
14-
def _missing_(cls: Type[RoborockEnum], key) -> str:
14+
def _missing_(cls: Type[RoborockEnum], key) -> RoborockEnum:
1515
if hasattr(cls, "missing"):
1616
_LOGGER.warning(f"Missing {cls.__name__} code: {key} - defaulting to 'missing'")
1717
return cls.missing # type: ignore
18-
_LOGGER.warning(f"Missing {cls.__name__} code: {key} - defaulting to {cls.keys()[0]}")
19-
return cls.keys()[0]
18+
default_value = next((item for item in cls))
19+
_LOGGER.warning(f"Missing {cls.__name__} code: {key} - defaulting to {default_value}")
20+
return default_value
2021

2122
@classmethod
2223
def as_dict(cls: Type[RoborockEnum]):
23-
return {i.value: i.name for i in cls if i.name != "missing"}
24+
return {i.name: i.value for i in cls if i.name != "missing"}
2425

2526
@classmethod
2627
def as_enum_dict(cls: Type[RoborockEnum]):

0 commit comments

Comments
 (0)