mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
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
@ -50,6 +50,11 @@ PLATFORMS_BY_TYPE = {
|
|||||||
Platform.LOCK,
|
Platform.LOCK,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
],
|
],
|
||||||
|
SupportedModels.LOCK_PRO.value: [
|
||||||
|
Platform.BINARY_SENSOR,
|
||||||
|
Platform.LOCK,
|
||||||
|
Platform.SENSOR,
|
||||||
|
],
|
||||||
SupportedModels.BLIND_TILT.value: [
|
SupportedModels.BLIND_TILT.value: [
|
||||||
Platform.COVER,
|
Platform.COVER,
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -66,6 +71,7 @@ CLASS_BY_DEVICE = {
|
|||||||
SupportedModels.LIGHT_STRIP.value: switchbot.SwitchbotLightStrip,
|
SupportedModels.LIGHT_STRIP.value: switchbot.SwitchbotLightStrip,
|
||||||
SupportedModels.HUMIDIFIER.value: switchbot.SwitchbotHumidifier,
|
SupportedModels.HUMIDIFIER.value: switchbot.SwitchbotHumidifier,
|
||||||
SupportedModels.LOCK.value: switchbot.SwitchbotLock,
|
SupportedModels.LOCK.value: switchbot.SwitchbotLock,
|
||||||
|
SupportedModels.LOCK_PRO.value: switchbot.SwitchbotLock,
|
||||||
SupportedModels.BLIND_TILT.value: switchbot.SwitchbotBlindTilt,
|
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),
|
key_id=entry.data.get(CONF_KEY_ID),
|
||||||
encryption_key=entry.data.get(CONF_ENCRYPTION_KEY),
|
encryption_key=entry.data.get(CONF_ENCRYPTION_KEY),
|
||||||
retry_count=entry.options[CONF_RETRY_COUNT],
|
retry_count=entry.options[CONF_RETRY_COUNT],
|
||||||
|
model=switchbot_model,
|
||||||
)
|
)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
|
@ -11,7 +11,6 @@ from switchbot import (
|
|||||||
SwitchbotApiError,
|
SwitchbotApiError,
|
||||||
SwitchbotAuthenticationError,
|
SwitchbotAuthenticationError,
|
||||||
SwitchbotLock,
|
SwitchbotLock,
|
||||||
SwitchbotModel,
|
|
||||||
parse_advertisement_data,
|
parse_advertisement_data,
|
||||||
)
|
)
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -44,6 +43,7 @@ from .const import (
|
|||||||
DEFAULT_RETRY_COUNT,
|
DEFAULT_RETRY_COUNT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
NON_CONNECTABLE_SUPPORTED_MODEL_TYPES,
|
NON_CONNECTABLE_SUPPORTED_MODEL_TYPES,
|
||||||
|
SUPPORTED_LOCK_MODELS,
|
||||||
SUPPORTED_MODEL_TYPES,
|
SUPPORTED_MODEL_TYPES,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"name": data["modelFriendlyName"],
|
"name": data["modelFriendlyName"],
|
||||||
"address": short_address(discovery_info.address),
|
"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()
|
return await self.async_step_lock_choose_method()
|
||||||
if self._discovered_adv.data["isEncrypted"]:
|
if self._discovered_adv.data["isEncrypted"]:
|
||||||
return await self.async_step_password()
|
return await self.async_step_password()
|
||||||
@ -240,6 +240,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
self._discovered_adv.device,
|
self._discovered_adv.device,
|
||||||
user_input[CONF_KEY_ID],
|
user_input[CONF_KEY_ID],
|
||||||
user_input[CONF_ENCRYPTION_KEY],
|
user_input[CONF_ENCRYPTION_KEY],
|
||||||
|
model=self._discovered_adv.data["modelName"],
|
||||||
):
|
):
|
||||||
errors = {
|
errors = {
|
||||||
"base": "encryption_key_invalid",
|
"base": "encryption_key_invalid",
|
||||||
@ -305,7 +306,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
device_adv = self._discovered_advs[user_input[CONF_ADDRESS]]
|
device_adv = self._discovered_advs[user_input[CONF_ADDRESS]]
|
||||||
await self._async_set_device(device_adv)
|
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()
|
return await self.async_step_lock_choose_method()
|
||||||
if device_adv.data["isEncrypted"]:
|
if device_adv.data["isEncrypted"]:
|
||||||
return await self.async_step_password()
|
return await self.async_step_password()
|
||||||
@ -317,7 +318,7 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
# or simply confirm it
|
# or simply confirm it
|
||||||
device_adv = list(self._discovered_advs.values())[0]
|
device_adv = list(self._discovered_advs.values())[0]
|
||||||
await self._async_set_device(device_adv)
|
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()
|
return await self.async_step_lock_choose_method()
|
||||||
if device_adv.data["isEncrypted"]:
|
if device_adv.data["isEncrypted"]:
|
||||||
return await self.async_step_password()
|
return await self.async_step_password()
|
||||||
|
@ -26,6 +26,7 @@ class SupportedModels(StrEnum):
|
|||||||
MOTION = "motion"
|
MOTION = "motion"
|
||||||
HUMIDIFIER = "humidifier"
|
HUMIDIFIER = "humidifier"
|
||||||
LOCK = "lock"
|
LOCK = "lock"
|
||||||
|
LOCK_PRO = "lock_pro"
|
||||||
BLIND_TILT = "blind_tilt"
|
BLIND_TILT = "blind_tilt"
|
||||||
HUB2 = "hub2"
|
HUB2 = "hub2"
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ CONNECTABLE_SUPPORTED_MODEL_TYPES = {
|
|||||||
SwitchbotModel.CEILING_LIGHT: SupportedModels.CEILING_LIGHT,
|
SwitchbotModel.CEILING_LIGHT: SupportedModels.CEILING_LIGHT,
|
||||||
SwitchbotModel.HUMIDIFIER: SupportedModels.HUMIDIFIER,
|
SwitchbotModel.HUMIDIFIER: SupportedModels.HUMIDIFIER,
|
||||||
SwitchbotModel.LOCK: SupportedModels.LOCK,
|
SwitchbotModel.LOCK: SupportedModels.LOCK,
|
||||||
|
SwitchbotModel.LOCK_PRO: SupportedModels.LOCK_PRO,
|
||||||
SwitchbotModel.BLIND_TILT: SupportedModels.BLIND_TILT,
|
SwitchbotModel.BLIND_TILT: SupportedModels.BLIND_TILT,
|
||||||
SwitchbotModel.HUB2: SupportedModels.HUB2,
|
SwitchbotModel.HUB2: SupportedModels.HUB2,
|
||||||
}
|
}
|
||||||
@ -54,6 +56,7 @@ SUPPORTED_MODEL_TYPES = (
|
|||||||
CONNECTABLE_SUPPORTED_MODEL_TYPES | NON_CONNECTABLE_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 = {
|
HASS_SENSOR_TYPE_TO_SWITCHBOT_MODEL = {
|
||||||
str(v): k for k, v in SUPPORTED_MODEL_TYPES.items()
|
str(v): k for k, v in SUPPORTED_MODEL_TYPES.items()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user