mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Fix wrong DPTypes returned by Tuya's cloud (#127860)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
456b80e6ae
commit
5901c543da
@ -17,6 +17,17 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from .const import DOMAIN, LOGGER, TUYA_HA_SIGNAL_UPDATE_ENTITY, DPCode, DPType
|
from .const import DOMAIN, LOGGER, TUYA_HA_SIGNAL_UPDATE_ENTITY, DPCode, DPType
|
||||||
from .util import remap_value
|
from .util import remap_value
|
||||||
|
|
||||||
|
_DPTYPE_MAPPING: dict[str, DPType] = {
|
||||||
|
"Bitmap": DPType.RAW,
|
||||||
|
"bitmap": DPType.RAW,
|
||||||
|
"bool": DPType.BOOLEAN,
|
||||||
|
"enum": DPType.ENUM,
|
||||||
|
"json": DPType.JSON,
|
||||||
|
"raw": DPType.RAW,
|
||||||
|
"string": DPType.STRING,
|
||||||
|
"value": DPType.INTEGER,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class IntegerTypeData:
|
class IntegerTypeData:
|
||||||
@ -256,7 +267,13 @@ class TuyaEntity(Entity):
|
|||||||
order = ["function", "status_range"]
|
order = ["function", "status_range"]
|
||||||
for key in order:
|
for key in order:
|
||||||
if dpcode in getattr(self.device, key):
|
if dpcode in getattr(self.device, key):
|
||||||
return DPType(getattr(self.device, key)[dpcode].type)
|
current_type = getattr(self.device, key)[dpcode].type
|
||||||
|
try:
|
||||||
|
return DPType(current_type)
|
||||||
|
except ValueError:
|
||||||
|
# Sometimes, we get ill-formed DPTypes from the cloud,
|
||||||
|
# this fixes them and maps them to the correct DPType.
|
||||||
|
return _DPTYPE_MAPPING.get(current_type)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user