Skip to content

Commit

Permalink
Fix some dps doesn't have high level type . (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Mar 16, 2024
1 parent 9f0ab19 commit 2982119
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions custom_components/localtuya/core/ha_entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def get_dp_values(dp: str, dps_data: dict, req_info: CLOUD_VALUE = None) -> dict
if not dp_values or not (dp_values := json.loads(dp_values)):
return

# Some DPS doesn't have the type, in high level data.
if not dp_type and (_type := dp_values.get("type")):
dp_type = _type.capitalize()

# Integer values: min, max, scale, step
if dp_values and dp_type == DPType.INTEGER:
# We only need the scaling factor, other values will be scaled from via later on.
Expand Down
2 changes: 0 additions & 2 deletions custom_components/localtuya/core/ha_entities/fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,3 @@ def localtuya_fan(fwd, rev, min_speed, max_speed, order, dp_type):
FANS["fskg"] = FANS["fs"]
# Air Purifier
FANS["kj"] = FANS["fs"]
# Dehumidifier
# FANS["cs"] = FANS["fs"]
18 changes: 15 additions & 3 deletions custom_components/localtuya/core/ha_entities/humidifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
EntityCategory,
CLOUD_VALUE,
)
from homeassistant.components.humidifier import HumidifierDeviceClass
from homeassistant.components.humidifier import (
HumidifierDeviceClass,
ATTR_MAX_HUMIDITY,
ATTR_MIN_HUMIDITY,
DEFAULT_MAX_HUMIDITY,
DEFAULT_MIN_HUMIDITY,
)

CONF_HUMIDIFIER_SET_HUMIDITY_DP = "humidifier_set_humidity_dp"
CONF_HUMIDIFIER_CURRENT_HUMIDITY_DP = "humidifier_current_humidity_dp"
Expand All @@ -25,9 +31,15 @@ def localtuya_humidifier(modes):
"""Define localtuya fan configs"""

data = {
"humidifier_available_modes": CLOUD_VALUE(
CONF_HUMIDIFIER_AVAILABLE_MODES: CLOUD_VALUE(
modes, CONF_HUMIDIFIER_MODE_DP, "range", dict
)
),
ATTR_MIN_HUMIDITY: CLOUD_VALUE(
DEFAULT_MIN_HUMIDITY, CONF_HUMIDIFIER_SET_HUMIDITY_DP, "min"
),
ATTR_MAX_HUMIDITY: CLOUD_VALUE(
DEFAULT_MAX_HUMIDITY, CONF_HUMIDIFIER_SET_HUMIDITY_DP, "max"
),
}
return data

Expand Down
7 changes: 7 additions & 0 deletions custom_components/localtuya/core/ha_entities/selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,13 @@ def localtuya_selector(options):
{"small": "Low", "middle": "Medium", "large": "High"}
),
),
LocalTuyaEntity(
id=DPCode.FAN_SPEED_ENUM,
name="Fan Speed",
entity_category=EntityCategory.CONFIG,
icon="mdi:fan",
custom_configs=localtuya_selector({"low": "Low", "high": "High"}),
),
),
# sous vide cookers
# https://developer.tuya.com/en/docs/iot/f?id=K9r2v9hgmyk3h
Expand Down

0 comments on commit 2982119

Please sign in to comment.