diff --git a/homeassistant/components/switchbot/__init__.py b/homeassistant/components/switchbot/__init__.py index 82860db6745..7bf02ed37b6 100644 --- a/homeassistant/components/switchbot/__init__.py +++ b/homeassistant/components/switchbot/__init__.py @@ -50,6 +50,11 @@ PLATFORMS_BY_TYPE = { Platform.LOCK, Platform.SENSOR, ], + SupportedModels.LOCK_PRO.value: [ + Platform.BINARY_SENSOR, + Platform.LOCK, + Platform.SENSOR, + ], SupportedModels.BLIND_TILT.value: [ Platform.COVER, Platform.BINARY_SENSOR, @@ -66,6 +71,7 @@ CLASS_BY_DEVICE = { SupportedModels.LIGHT_STRIP.value: switchbot.SwitchbotLightStrip, SupportedModels.HUMIDIFIER.value: switchbot.SwitchbotHumidifier, SupportedModels.LOCK.value: switchbot.SwitchbotLock, + SupportedModels.LOCK_PRO.value: switchbot.SwitchbotLock, SupportedModels.BLIND_TILT.value: switchbot.SwitchbotBlindTilt, } @@ -118,6 +124,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: key_id=entry.data.get(CONF_KEY_ID), encryption_key=entry.data.get(CONF_ENCRYPTION_KEY), retry_count=entry.options[CONF_RETRY_COUNT], + model=switchbot_model, ) except ValueError as error: raise ConfigEntryNotReady( diff --git a/homeassistant/components/switchbot/config_flow.py b/homeassistant/components/switchbot/config_flow.py index bb69da52239..a1c947fd611 100644 --- a/homeassistant/components/switchbot/config_flow.py +++ b/homeassistant/components/switchbot/config_flow.py @@ -11,7 +11,6 @@ from switchbot import ( SwitchbotApiError, SwitchbotAuthenticationError, SwitchbotLock, - SwitchbotModel, parse_advertisement_data, ) import voluptuous as vol @@ -44,6 +43,7 @@ from .const import ( DEFAULT_RETRY_COUNT, DOMAIN, NON_CONNECTABLE_SUPPORTED_MODEL_TYPES, + SUPPORTED_LOCK_MODELS, SUPPORTED_MODEL_TYPES, ) @@ -109,7 +109,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN): "name": data["modelFriendlyName"], "address": short_address(discovery_info.address), } - if model_name == SwitchbotModel.LOCK: + if model_name in SUPPORTED_LOCK_MODELS: return await self.async_step_lock_choose_method() if self._discovered_adv.data["isEncrypted"]: return await self.async_step_password() @@ -240,6 +240,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN): self._discovered_adv.device, user_input[CONF_KEY_ID], user_input[CONF_ENCRYPTION_KEY], + model=self._discovered_adv.data["modelName"], ): errors = { "base": "encryption_key_invalid", @@ -305,7 +306,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN): if user_input is not None: device_adv = self._discovered_advs[user_input[CONF_ADDRESS]] await self._async_set_device(device_adv) - if device_adv.data.get("modelName") == SwitchbotModel.LOCK: + if device_adv.data.get("modelName") in SUPPORTED_LOCK_MODELS: return await self.async_step_lock_choose_method() if device_adv.data["isEncrypted"]: return await self.async_step_password() @@ -317,7 +318,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN): # or simply confirm it device_adv = list(self._discovered_advs.values())[0] await self._async_set_device(device_adv) - if device_adv.data.get("modelName") == SwitchbotModel.LOCK: + if device_adv.data.get("modelName") in SUPPORTED_LOCK_MODELS: return await self.async_step_lock_choose_method() if device_adv.data["isEncrypted"]: return await self.async_step_password() diff --git a/homeassistant/components/switchbot/const.py b/homeassistant/components/switchbot/const.py index 7e7a1d185f2..0a1ac01e530 100644 --- a/homeassistant/components/switchbot/const.py +++ b/homeassistant/components/switchbot/const.py @@ -26,6 +26,7 @@ class SupportedModels(StrEnum): MOTION = "motion" HUMIDIFIER = "humidifier" LOCK = "lock" + LOCK_PRO = "lock_pro" BLIND_TILT = "blind_tilt" HUB2 = "hub2" @@ -39,6 +40,7 @@ CONNECTABLE_SUPPORTED_MODEL_TYPES = { SwitchbotModel.CEILING_LIGHT: SupportedModels.CEILING_LIGHT, SwitchbotModel.HUMIDIFIER: SupportedModels.HUMIDIFIER, SwitchbotModel.LOCK: SupportedModels.LOCK, + SwitchbotModel.LOCK_PRO: SupportedModels.LOCK_PRO, SwitchbotModel.BLIND_TILT: SupportedModels.BLIND_TILT, SwitchbotModel.HUB2: SupportedModels.HUB2, } @@ -54,6 +56,7 @@ SUPPORTED_MODEL_TYPES = ( CONNECTABLE_SUPPORTED_MODEL_TYPES | NON_CONNECTABLE_SUPPORTED_MODEL_TYPES ) +SUPPORTED_LOCK_MODELS = {SwitchbotModel.LOCK, SwitchbotModel.LOCK_PRO} HASS_SENSOR_TYPE_TO_SWITCHBOT_MODEL = { str(v): k for k, v in SUPPORTED_MODEL_TYPES.items()