diff --git a/custom_components/tuya_ble/button.py b/custom_components/tuya_ble/button.py index 0586a648..9d5074f6 100644 --- a/custom_components/tuya_ble/button.py +++ b/custom_components/tuya_ble/button.py @@ -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 [ diff --git a/custom_components/tuya_ble/config_flow.py b/custom_components/tuya_ble/config_flow.py index 75239438..c77068aa 100644 --- a/custom_components/tuya_ble/config_flow.py +++ b/custom_components/tuya_ble/config_flow.py @@ -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", @@ -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] diff --git a/custom_components/tuya_ble/devices.py b/custom_components/tuya_ble/devices.py index 53e9fe17..866d2df1 100644 --- a/custom_components/tuya_ble/devices.py +++ b/custom_components/tuya_ble/devices.py @@ -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", diff --git a/custom_components/tuya_ble/number.py b/custom_components/tuya_ble/number.py index b7b3a5ad..dd20339e 100644 --- a/custom_components/tuya_ble/number.py +++ b/custom_components/tuya_ble/number.py @@ -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 [ diff --git a/custom_components/tuya_ble/select.py b/custom_components/tuya_ble/select.py index b697fb19..c66ec528 100644 --- a/custom_components/tuya_ble/select.py +++ b/custom_components/tuya_ble/select.py @@ -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 [ diff --git a/custom_components/tuya_ble/sensor.py b/custom_components/tuya_ble/sensor.py index 6d1b936d..28d0aa6c 100644 --- a/custom_components/tuya_ble/sensor.py +++ b/custom_components/tuya_ble/sensor.py @@ -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 [ diff --git a/custom_components/tuya_ble/switch.py b/custom_components/tuya_ble/switch.py index a401b44a..25eaf62b 100644 --- a/custom_components/tuya_ble/switch.py +++ b/custom_components/tuya_ble/switch.py @@ -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),