Skip to content

Commit

Permalink
Draft to add CUBETOUCH 1s support
Browse files Browse the repository at this point in the history
  • Loading branch information
PlusPlus-ua committed Apr 28, 2023
1 parent a99fa97 commit 9c3f484
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 44 deletions.
10 changes: 6 additions & 4 deletions custom_components/tuya_ble/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ class TuyaBLECategoryButtonMapping:
mapping: dict[str, TuyaBLECategoryButtonMapping] = {
"szjqr": TuyaBLECategoryButtonMapping(
products={
"xhf790if": # CubeTouch II
[
TuyaBLEFingerbotModeMapping(dp_id=1),
],
**dict.fromkeys(
["3yqdo5yt", "xhf790if"], # CubeTouch 1s and II
[
TuyaBLEFingerbotModeMapping(dp_id=1),
],
),
**dict.fromkeys(
["blliqpsj", "yiihr7zh"], # Fingerbot Plus
[
Expand Down
10 changes: 8 additions & 2 deletions custom_components/tuya_ble/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ def _show_login_form(
user_input[CONF_COUNTRY_CODE] = country.name
break

def_country = pycountry.countries.get(alpha_2=flow.hass.config.country)
def_country_name: str | None = None
try:
def_country = pycountry.countries.get(alpha_2=flow.hass.config.country)
if def_country:
def_country_name = def_country.name
except:
pass

return flow.async_show_form(
step_id="login",
Expand All @@ -120,7 +126,7 @@ def _show_login_form(
vol.Required(
CONF_COUNTRY_CODE,
default=user_input.get(
CONF_COUNTRY_CODE, def_country.name),
CONF_COUNTRY_CODE, def_country_name),
): vol.In(
# We don't pass a dict {code:name} because country codes can be duplicate.
[country.name for country in TUYA_COUNTRIES]
Expand Down
12 changes: 12 additions & 0 deletions custom_components/tuya_ble/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ class TuyaBLECategoryInfo:
),
"szjqr": TuyaBLECategoryInfo(
products={
"3yqdo5yt": # device product_id
TuyaBLEProductInfo(
name="CUBETOUCH 1s",
fingerbot=TuyaBLEFingerbotInfo(
switch=1,
mode=2,
up_position=5,
down_position=6,
hold_time=3,
reverse_positions=4,
),
),
"xhf790if": # device product_id
TuyaBLEProductInfo(
name="CubeTouch II",
Expand Down
30 changes: 16 additions & 14 deletions custom_components/tuya_ble/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,24 @@ class TuyaBLECategoryNumberMapping:
),
"szjqr": TuyaBLECategoryNumberMapping(
products={
"xhf790if": # CubeTouch II
[
TuyaBLEHoldTimeMapping(dp_id=3),
TuyaBLENumberMapping(
dp_id=5,
description=TuyaBLEUpPositionDescription(
native_max_value=100,
**dict.fromkeys(
["3yqdo5yt", "xhf790if"], # CubeTouch 1s and II
[
TuyaBLEHoldTimeMapping(dp_id=3),
TuyaBLENumberMapping(
dp_id=5,
description=TuyaBLEUpPositionDescription(
native_max_value=100,
),
),
),
TuyaBLENumberMapping(
dp_id=6,
description=TuyaBLEDownPositionDescription(
native_min_value=0,
TuyaBLENumberMapping(
dp_id=6,
description=TuyaBLEDownPositionDescription(
native_min_value=0,
),
),
),
],
],
),
**dict.fromkeys(
["blliqpsj", "yiihr7zh"], # Fingerbot Plus
[
Expand Down
10 changes: 6 additions & 4 deletions custom_components/tuya_ble/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ class TuyaBLECategorySelectMapping:
),
"szjqr": TuyaBLECategorySelectMapping(
products={
"xhf790if": # CubeTouch II
[
TuyaBLEFingerbotModeMapping(dp_id=2),
],
**dict.fromkeys(
["3yqdo5yt", "xhf790if"], # CubeTouch 1s and II
[
TuyaBLEFingerbotModeMapping(dp_id=2),
],
),
**dict.fromkeys(
["blliqpsj", "yiihr7zh"], # Fingerbot Plus
[
Expand Down
42 changes: 22 additions & 20 deletions custom_components/tuya_ble/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,30 @@ class TuyaBLECategorySensorMapping:
),
"szjqr": TuyaBLECategorySensorMapping(
products={
"xhf790if": # CubeTouch II
[
TuyaBLESensorMapping(
dp_id=7,
description=SensorEntityDescription(
key="battery_charging",
device_class=SensorDeviceClass.ENUM,
entity_category=EntityCategory.DIAGNOSTIC,
options=[
BATTERY_NOT_CHARGING,
BATTERY_CHARGING,
BATTERY_CHARGED,
**dict.fromkeys(
["3yqdo5yt", "xhf790if"], # CubeTouch 1s and II
[
TuyaBLESensorMapping(
dp_id=7,
description=SensorEntityDescription(
key="battery_charging",
device_class=SensorDeviceClass.ENUM,
entity_category=EntityCategory.DIAGNOSTIC,
options=[
BATTERY_NOT_CHARGING,
BATTERY_CHARGING,
BATTERY_CHARGED,
],
),
icons=[
"mdi:battery",
"mdi:power-plug-battery",
"mdi:battery-check",
],
),
icons=[
"mdi:battery",
"mdi:power-plug-battery",
"mdi:battery-check",
],
),
TuyaBLEBatteryMapping(dp_id=8),
],
TuyaBLEBatteryMapping(dp_id=8),
],
),
**dict.fromkeys(
["blliqpsj", "yiihr7zh"], # Fingerbot Plus
[
Expand Down
19 changes: 19 additions & 0 deletions custom_components/tuya_ble/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ class TuyaBLECategorySwitchMapping:
),
"szjqr": TuyaBLECategorySwitchMapping(
products={
"3yqdo5yt": # CubeTouch 1s
[
TuyaBLEFingerbotSwitchMapping(dp_id=1),
TuyaBLEReversePositionsMapping(dp_id=4),
TuyaBLESwitchMapping(
dp_id=9,
description=SwitchEntityDescription(
key="power_saving",
entity_category=EntityCategory.CONFIG,
),
),
TuyaBLESwitchMapping(
dp_id=10,
description=SwitchEntityDescription(
key="tap_enable",
entity_category=EntityCategory.CONFIG,
),
),
],
"xhf790if": # CubeTouch II
[
TuyaBLEFingerbotSwitchMapping(dp_id=1),
Expand Down

0 comments on commit 9c3f484

Please sign in to comment.