Skip to content

Commit

Permalink
Refactoring Vacuums and there auto configure #158
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Mar 2, 2024
1 parent 27a6ed9 commit af4572d
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 37 deletions.
1 change: 1 addition & 0 deletions custom_components/localtuya/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
CONF_PAUSED_STATE = "paused_state"
CONF_RETURN_MODE = "return_mode"
CONF_STOP_STATUS = "stop_status"
CONF_PAUSE_DP = "pause_dp"

# number
CONF_MIN_VALUE = "min_value"
Expand Down
4 changes: 4 additions & 0 deletions custom_components/localtuya/core/ha_entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class DPCode(StrEnum):
BATTERY_PERCENTAGE = "battery_percentage" # Battery percentage
BATTERY_STATE = "battery_state" # Battery state
BATTERY_VALUE = "battery_value" # Battery value
BREAK_CLEAN = "break_clean"
BRIGHTNESS_MAX_1 = "brightness_max_1"
BRIGHTNESS_MAX_2 = "brightness_max_2"
BRIGHTNESS_MAX_3 = "brightness_max_3"
Expand Down Expand Up @@ -227,6 +228,7 @@ class DPCode(StrEnum):
DELAY_SET = "delay_set"
DEVICE_STATE1 = "device_state1"
DEVICE_STATE2 = "device_state2"
DIRECTION_CONTROL = "direction_control"
DISINFECTION = "disinfection"
DOORBELL = "doorbell"
DOORCONTACT_STATE = "doorcontact_state" # Status of door window sensor
Expand Down Expand Up @@ -586,6 +588,7 @@ class DPCode(StrEnum):
VOC_STATE = "voc_state"
VOC_VALUE = "voc_value"
VOICE_BT_PLAY = "voice_bt_play"
VOICE_LANGUAGE = "voice_language"
VOICE_MIC = "voice_mic"
VOICE_PLAY = "voice_play"
VOICE_SWITCH = "voice_switch"
Expand Down Expand Up @@ -615,5 +618,6 @@ class DPCode(StrEnum):
WORK_POWER = "work_power"
WORK_STATE = "work_state"
WORK_STATUS = "work_status"
Y_MOP = "y_mop"
ZONE_ATTRIBUTE = "zone_attribute"
ZONE_NUMBER = "zone_number"
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,4 @@ def localtuya_binarySensor(state_on="1"):
BINARY_SENSORS["cs"] = FAULT_SENSOR
BINARY_SENSORS["jsq"] = FAULT_SENSOR
BINARY_SENSORS["kt"] = FAULT_SENSOR
BINARY_SENSORS["sd"] = FAULT_SENSOR
144 changes: 120 additions & 24 deletions custom_components/localtuya/core/ha_entities/selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,51 @@ def localtuya_selector(options):
id=DPCode.CUP_NUMBER,
name="Cups",
icon="mdi:numeric",
custom_configs=localtuya_selector("1,2,3,4,5,6,7,8,9,10,11,12"),
custom_configs=localtuya_selector(
{
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"9": "9",
"10": "10",
"11": "11",
"12": "12",
}
),
),
LocalTuyaEntity(
id=DPCode.CONCENTRATION_SET,
name="Concentration",
icon="mdi:altimeter",
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector("regular,middle,bold"),
custom_configs=localtuya_selector(
{"regular": "REGULAR", "middle": "MIDDLE", "bold": "BOLD"}
),
),
LocalTuyaEntity(
id=DPCode.MATERIAL,
name="Material",
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector("bean,powder"),
custom_configs=localtuya_selector({"bean": "BEAN", "powder": "POWDER"}),
),
LocalTuyaEntity(
id=DPCode.MODE,
name="Mode",
icon="mdi:coffee",
custom_configs=localtuya_selector(
"espresso,americano,machiatto,caffe_latte,cafe_mocha,cappuccino"
{
"espresso": "Espresso",
"americano": "Americano",
"machiatto": "Machiatto",
"caffe_latte": "Latte",
"caffe_mocha": "Mocha",
"cappuccino": "Cappuccino",
}
),
),
),
Expand Down Expand Up @@ -428,21 +452,31 @@ def localtuya_selector(options):
id=DPCode.ALARM_VOLUME,
name="Volume",
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector("low,middle,high,mute"),
custom_configs=localtuya_selector(
{"low": "LOW", "middle": "MIDDLE", "high": "HIGH", "mute": "MUTE"}
),
),
LocalTuyaEntity(
id=DPCode.ALARM_STATE,
name="State",
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector(
"alarm_sound,alarm_light,alarm_sound_light,normal"
{
"alarm_sound": "Sound",
"alarm_light": "Light",
"alarm_sound_light": "Sound and Light",
"normal": "NNORMAL",
}
),
),
LocalTuyaEntity(
id=DPCode.BRIGHT_STATE,
name="Brightness",
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector("low,middle,high,strong"),
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector(
{"low": "LOW", "middle": "MIDDLE", "high": "HIGH", "strong": "MAX"}
),
),
),
# Smart Camera
Expand Down Expand Up @@ -560,19 +594,25 @@ def localtuya_selector(options):
id=DPCode.LED_TYPE_1,
entity_category=EntityCategory.CONFIG,
name="Led Type 1",
custom_configs=localtuya_selector("led,incandescent,halogen"),
custom_configs=localtuya_selector(
{"led": "Led", "incandescent": "Incandescent", "halogen": "Halogen"}
),
),
LocalTuyaEntity(
id=DPCode.LED_TYPE_2,
entity_category=EntityCategory.CONFIG,
name="Led Type 2",
custom_configs=localtuya_selector("led,incandescent,halogen"),
custom_configs=localtuya_selector(
{"led": "Led", "incandescent": "Incandescent", "halogen": "Halogen"}
),
),
LocalTuyaEntity(
id=DPCode.LED_TYPE_3,
entity_category=EntityCategory.CONFIG,
name="Led Type 3",
custom_configs=localtuya_selector("led,incandescent,halogen"),
custom_configs=localtuya_selector(
{"led": "Led", "incandescent": "Incandescent", "halogen": "Halogen"}
),
),
),
# Dimmer
Expand All @@ -582,13 +622,17 @@ def localtuya_selector(options):
id=DPCode.LED_TYPE_1,
entity_category=EntityCategory.CONFIG,
name="Led Type 1",
custom_configs=localtuya_selector("led,incandescent,halogen"),
custom_configs=localtuya_selector(
{"led": "Led", "incandescent": "Incandescent", "halogen": "Halogen"}
),
),
LocalTuyaEntity(
id=DPCode.LED_TYPE_2,
entity_category=EntityCategory.CONFIG,
name="Led Type 2",
custom_configs=localtuya_selector("led,incandescent,halogen"),
custom_configs=localtuya_selector(
{"led": "Led", "incandescent": "Incandescent", "halogen": "Halogen"}
),
),
),
# Fingerbot
Expand All @@ -597,7 +641,9 @@ def localtuya_selector(options):
id=DPCode.MODE,
entity_category=EntityCategory.CONFIG,
name="Fingerbot Mode",
custom_configs=localtuya_selector("click,switch,toggle"),
custom_configs=localtuya_selector(
{"click": "Click", "switch": "Switch", "toggle": "Toggle"}
),
),
),
# Robot Vacuum
Expand All @@ -608,22 +654,39 @@ def localtuya_selector(options):
entity_category=EntityCategory.CONFIG,
icon="mdi:water-opacity",
name="Water Tank Adjustment",
custom_configs=localtuya_selector("low,middle,high,closed"),
custom_configs=localtuya_selector(
{"low": "Low", "middle": "Middle", "high": "High", "closed": "Closed"}
),
),
LocalTuyaEntity(
id=DPCode.COLLECTION_MODE,
entity_category=EntityCategory.CONFIG,
icon="mdi:air-filter",
name="Dust Collection Mode",
custom_configs=localtuya_selector("small,middle,large"),
custom_configs=localtuya_selector(
{"small": "Small", "middle": "Middle", "large": "Large"}
),
),
LocalTuyaEntity(
id=DPCode.VOICE_LANGUAGE,
entity_category=EntityCategory.CONFIG,
icon="mdi:air-filter",
name="Dust Collection Mode",
custom_configs=localtuya_selector({"cn": "Chinese", "en": "English"}),
),
LocalTuyaEntity(
id=DPCode.MODE,
id=DPCode.DIRECTION_CONTROL,
entity_category=EntityCategory.CONFIG,
icon="mdi:layers-outline",
name="Mode",
icon="mdi:arrow-all",
name="Direction",
custom_configs=localtuya_selector(
"standby,random,smart,wall_follow,mop,spiral,left_spiral,right_spiral,right_bow,left_bow,partial_bow,chargego"
{
"foward": "Forward",
"backward": "Backward",
"turn_left": "Left",
"turn_right": "Right",
"stop": "Stop",
}
),
),
),
Expand Down Expand Up @@ -662,7 +725,9 @@ def localtuya_selector(options):
entity_category=EntityCategory.CONFIG,
icon="mdi:ceiling-fan-light",
name="Light mode",
custom_configs=localtuya_selector("white,colour,colourful"),
custom_configs=localtuya_selector(
{"white": "White", "colour": "Colour", "colourful": "Colourful"}
),
),
LocalTuyaEntity(
id=DPCode.COUNTDOWN,
Expand Down Expand Up @@ -713,23 +778,45 @@ def localtuya_selector(options):
entity_category=EntityCategory.CONFIG,
icon="mdi:spray",
name="Spraying mode",
custom_configs=localtuya_selector("auto,health,baby,sleep,humidity,work"),
custom_configs=localtuya_selector(
{
"auto": "AUTO",
"health": "Health",
"baby": "BABY",
"sleep": "SLEEP",
"humidity": "HUMIDITY",
"work": "WORK",
}
),
),
LocalTuyaEntity(
id=DPCode.LEVEL,
entity_category=EntityCategory.CONFIG,
icon="mdi:spray",
name="Spraying level",
custom_configs=localtuya_selector(
"level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10"
{
"level_1": "LEVEL 1",
"level_2": "LEVEL 2",
"level_3": "LEVEL 3",
"level_4": "LEVEL 4",
"level_5": "LEVEL 5",
"level_6": "LEVEL 6",
"level_7": "LEVEL 7",
"level_8": "LEVEL 8",
"level_9": "LEVEL 9",
"level_10": "LEVEL 10",
}
),
),
LocalTuyaEntity(
id=DPCode.MOODLIGHTING,
entity_category=EntityCategory.CONFIG,
icon="mdi:lightbulb-multiple",
name="Mood light",
custom_configs=localtuya_selector("1,2,3,4,5"),
custom_configs=localtuya_selector(
{"1": "1", "2": "2", "3": "3", "4": "4", "5": "5"}
),
),
LocalTuyaEntity(
id=DPCode.COUNTDOWN,
Expand Down Expand Up @@ -803,7 +890,16 @@ def localtuya_selector(options):
entity_category=EntityCategory.CONFIG,
name="Cooking Mode",
custom_configs=localtuya_selector(
"vegetables,meat,shrimp,fish,chicken,drumsticks,beef,rice"
{
"vegetables": "Vegetables",
"meat": "Meat",
"shrimp": "Shrimp",
"fish": "Fish",
"chicken": "Chicken",
"drumsticks": "Drumsticks",
"beef": "Beef",
"rice": "Rice",
}
),
),
),
Expand Down
24 changes: 24 additions & 0 deletions custom_components/localtuya/core/ha_entities/switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,30 @@
icon="mdi:account-voice",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.SEEK,
name="Device locating",
icon="mdi:select-marker",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.RESET_MAP,
name="Map Resetting",
icon="mdi:backup-restore",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.BREAK_CLEAN,
name="Resumable Cleaning",
icon="mdi:cog-play-outline",
entity_category=EntityCategory.CONFIG,
),
LocalTuyaEntity(
id=DPCode.Y_MOP,
name="Mop Y",
icon="mdi:dots-vertical",
entity_category=EntityCategory.CONFIG,
),
),
# Siren Alarm
# https://developer.tuya.com/en/docs/iot/categorysgbj?id=Kaiuz37tlpbnu
Expand Down
Loading

0 comments on commit af4572d

Please sign in to comment.