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
5dd91db5c0
commit
d8d000f279
1 changed files with 18 additions and 1 deletions
|
@ -17,6 +17,17 @@ from homeassistant.helpers.entity import Entity
|
|||
from .const import DOMAIN, LOGGER, TUYA_HA_SIGNAL_UPDATE_ENTITY, DPCode, DPType
|
||||
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
|
||||
class IntegerTypeData:
|
||||
|
@ -256,7 +267,13 @@ class TuyaEntity(Entity):
|
|||
order = ["function", "status_range"]
|
||||
for key in order:
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue