mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix Unable to serialize to JSON
error in Xiaomi Miio (#56929)
This commit is contained in:
parent
2730a27fd0
commit
4cdbd3c576
@ -1,6 +1,7 @@
|
|||||||
"""Support for Xiaomi Mi Air Purifier and Xiaomi Mi Air Humidifier."""
|
"""Support for Xiaomi Mi Air Purifier and Xiaomi Mi Air Humidifier."""
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from enum import Enum
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
|
||||||
@ -363,13 +364,21 @@ class XiaomiGenericAirPurifier(XiaomiGenericDevice):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _extract_value_from_attribute(state, attribute):
|
||||||
|
value = getattr(state, attribute)
|
||||||
|
if isinstance(value, Enum):
|
||||||
|
return value.value
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self):
|
def _handle_coordinator_update(self):
|
||||||
"""Fetch state from the device."""
|
"""Fetch state from the device."""
|
||||||
self._state = self.coordinator.data.is_on
|
self._state = self.coordinator.data.is_on
|
||||||
self._state_attrs.update(
|
self._state_attrs.update(
|
||||||
{
|
{
|
||||||
key: getattr(self.coordinator.data, value)
|
key: self._extract_value_from_attribute(self.coordinator.data, value)
|
||||||
for key, value in self._available_attributes.items()
|
for key, value in self._available_attributes.items()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -434,7 +443,7 @@ class XiaomiAirPurifier(XiaomiGenericAirPurifier):
|
|||||||
self._state = self.coordinator.data.is_on
|
self._state = self.coordinator.data.is_on
|
||||||
self._state_attrs.update(
|
self._state_attrs.update(
|
||||||
{
|
{
|
||||||
key: getattr(self.coordinator.data, value)
|
key: self._extract_value_from_attribute(self.coordinator.data, value)
|
||||||
for key, value in self._available_attributes.items()
|
for key, value in self._available_attributes.items()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user