Add support for Switchbot Lock Pro (#119326)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
fb25902de9
commit
ecadaf314d
3 changed files with 15 additions and 4 deletions
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue