Complete Switch/Socket/Power Strip device support for Tuya (#58106)

This commit is contained in:
Franck Nijhof 2021-10-20 19:08:43 +02:00 committed by GitHub
parent 5fc2897c08
commit 3e57d0d3d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 1 deletions

View file

@ -75,6 +75,9 @@ CONF_PASSWORD = "password"
CONF_COUNTRY_CODE = "country_code"
CONF_APP_TYPE = "tuya_app_type"
DEVICE_CLASS_TUYA_RELAY_STATUS = "tuya__relay_status"
DEVICE_CLASS_TUYA_LIGHT_MODE = "tuya__light_mode"
TUYA_DISCOVERY_NEW = "tuya_discovery_new"
TUYA_HA_SIGNAL_UPDATE_ENTITY = "tuya_entry_update"
@ -164,6 +167,7 @@ class DPCode(str, Enum):
HUMIDITY_SET = "humidity_set" # Humidity setting
HUMIDITY_VALUE = "humidity_value" # Humidity
LIGHT = "light" # Light
LIGHT_MODE = "light_mode"
LOCK = "lock" # Lock / Child lock
MATERIAL = "material" # Material
MODE = "mode" # Working mode / Mode
@ -183,6 +187,7 @@ class DPCode(str, Enum):
PRESENCE_STATE = "presence_state"
PUMP_RESET = "pump_reset" # Water pump reset
RECORD_SWITCH = "record_switch" # Recording switch
RELAY_STATUS = "relay_status"
SEEK = "seek"
SENSITIVITY = "sensitivity" # Sensitivity
SHAKE = "shake" # Oscillating

View file

@ -105,6 +105,14 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
color_data=DPCode.COLOUR_DATA,
),
),
# Switch
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
"kg": (
TuyaLightEntityDescription(
key=DPCode.SWITCH_BACKLIGHT,
name="Backlight",
),
),
# Dimmer
# https://developer.tuya.com/en/docs/iot/tgq?id=Kaof8ke9il4k4
"tgq": (
@ -157,6 +165,14 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
),
}
# Socket (duplicate of `kg`)
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
LIGHTS["cz"] = LIGHTS["kg"]
# Power Socket (duplicate of `kg`)
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
LIGHTS["pc"] = LIGHTS["kg"]
@dataclass
class ColorTypeData:

View file

@ -15,7 +15,13 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HomeAssistantTuyaData
from .base import EnumTypeData, TuyaEntity
from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode
from .const import (
DEVICE_CLASS_TUYA_LIGHT_MODE,
DEVICE_CLASS_TUYA_RELAY_STATUS,
DOMAIN,
TUYA_DISCOVERY_NEW,
DPCode,
)
# All descriptions can be found here. Mostly the Enum data types in the
# default instructions set of each category end up being a select.
@ -46,6 +52,22 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
icon="mdi:coffee",
),
),
# Switch
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
"kg": (
SelectEntityDescription(
key=DPCode.RELAY_STATUS,
name="Power on Behavior",
device_class=DEVICE_CLASS_TUYA_RELAY_STATUS,
entity_category=ENTITY_CATEGORY_CONFIG,
),
SelectEntityDescription(
key=DPCode.LIGHT_MODE,
name="Indicator Light Mode",
device_class=DEVICE_CLASS_TUYA_LIGHT_MODE,
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
# Siren Alarm
# https://developer.tuya.com/en/docs/iot/categorysgbj?id=Kaiuz37tlpbnu
"sgbj": (
@ -63,6 +85,15 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
}
# Socket (duplicate of `kg`)
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
SELECTS["cz"] = SELECTS["kg"]
# Power Socket (duplicate of `kg`)
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
SELECTS["pc"] = SELECTS["kg"]
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:

View file

@ -0,0 +1,14 @@
{
"state": {
"tuya__light_mode": {
"none": "[%key:common::state::off%]",
"pos": "Indicate switch location",
"relay": "Indicate switch on/off state"
},
"tuya__relay_status": {
"last": "Remember last state",
"power_off": "[%key:common::state::off%]",
"power_on": "[%key:common::state::on%]"
}
}
}

View file

@ -0,0 +1,14 @@
{
"state": {
"tuya__light_mode": {
"none": "Off",
"pos": "Indicate switch location",
"relay": "Indicate switch on/off state"
},
"tuya__relay_status": {
"last": "Remember last state",
"power_off": "Off",
"power_on": "On"
}
}
}