Add support for SwitchBot Plug Mini (#76056)

This commit is contained in:
Eloston 2022-08-02 02:29:44 +00:00 committed by GitHub
parent 26e2ef8175
commit 44b6213217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 10 deletions

View File

@ -1046,8 +1046,8 @@ build.json @home-assistant/supervisor
/tests/components/switch/ @home-assistant/core
/homeassistant/components/switch_as_x/ @home-assistant/core
/tests/components/switch_as_x/ @home-assistant/core
/homeassistant/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas
/tests/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas
/homeassistant/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas @Eloston
/tests/components/switchbot/ @bdraco @danielhiversen @RenierM26 @murtas @Eloston
/homeassistant/components/switcher_kis/ @tomerfi @thecode
/tests/components/switcher_kis/ @tomerfi @thecode
/homeassistant/components/switchmate/ @danielhiversen @qiz-li

View File

@ -22,6 +22,7 @@ from .const import (
ATTR_CONTACT,
ATTR_CURTAIN,
ATTR_HYGROMETER,
ATTR_PLUG,
CONF_RETRY_COUNT,
DEFAULT_RETRY_COUNT,
DOMAIN,
@ -30,6 +31,7 @@ from .coordinator import SwitchbotDataUpdateCoordinator
PLATFORMS_BY_TYPE = {
ATTR_BOT: [Platform.SWITCH, Platform.SENSOR],
ATTR_PLUG: [Platform.SWITCH, Platform.SENSOR],
ATTR_CURTAIN: [Platform.COVER, Platform.BINARY_SENSOR, Platform.SENSOR],
ATTR_HYGROMETER: [Platform.SENSOR],
ATTR_CONTACT: [Platform.BINARY_SENSOR, Platform.SENSOR],
@ -37,6 +39,7 @@ PLATFORMS_BY_TYPE = {
CLASS_BY_DEVICE = {
ATTR_CURTAIN: switchbot.SwitchbotCurtain,
ATTR_BOT: switchbot.Switchbot,
ATTR_PLUG: switchbot.SwitchbotPlugMini,
}
_LOGGER = logging.getLogger(__name__)

View File

@ -7,12 +7,14 @@ ATTR_BOT = "bot"
ATTR_CURTAIN = "curtain"
ATTR_HYGROMETER = "hygrometer"
ATTR_CONTACT = "contact"
ATTR_PLUG = "plug"
DEFAULT_NAME = "Switchbot"
SUPPORTED_MODEL_TYPES = {
"WoHand": ATTR_BOT,
"WoCurtain": ATTR_CURTAIN,
"WoSensorTH": ATTR_HYGROMETER,
"WoContact": ATTR_CONTACT,
"WoPlug": ATTR_PLUG,
}
# Config Defaults

View File

@ -2,10 +2,16 @@
"domain": "switchbot",
"name": "SwitchBot",
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"requirements": ["PySwitchbot==0.16.0"],
"requirements": ["PySwitchbot==0.17.1"],
"config_flow": true,
"dependencies": ["bluetooth"],
"codeowners": ["@bdraco", "@danielhiversen", "@RenierM26", "@murtas"],
"codeowners": [
"@bdraco",
"@danielhiversen",
"@RenierM26",
"@murtas",
"@Eloston"
],
"bluetooth": [
{
"service_data_uuid": "0000fd3d-0000-1000-8000-00805f9b34fb"

View File

@ -33,6 +33,13 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
"wifi_rssi": SensorEntityDescription(
key="wifi_rssi",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
),
"battery": SensorEntityDescription(
key="battery",
native_unit_of_measurement=PERCENTAGE,
@ -98,7 +105,7 @@ class SwitchBotSensor(SwitchbotEntity, SensorEntity):
super().__init__(coordinator, unique_id, address, name=switchbot_name)
self._sensor = sensor
self._attr_unique_id = f"{unique_id}-{sensor}"
self._attr_name = f"{switchbot_name} {sensor.title()}"
self._attr_name = f"{switchbot_name} {sensor.replace('_', ' ').title()}"
self.entity_description = SENSOR_TYPES[sensor]
@property

View File

@ -33,7 +33,7 @@ async def async_setup_entry(
assert unique_id is not None
async_add_entities(
[
SwitchBotBotEntity(
SwitchBotSwitch(
coordinator,
unique_id,
entry.data[CONF_ADDRESS],
@ -44,8 +44,8 @@ async def async_setup_entry(
)
class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity):
"""Representation of a Switchbot."""
class SwitchBotSwitch(SwitchbotEntity, SwitchEntity, RestoreEntity):
"""Representation of a Switchbot switch."""
_attr_device_class = SwitchDeviceClass.SWITCH

View File

@ -37,7 +37,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1
# homeassistant.components.switchbot
PySwitchbot==0.16.0
PySwitchbot==0.17.1
# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1

View File

@ -33,7 +33,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1
# homeassistant.components.switchbot
PySwitchbot==0.16.0
PySwitchbot==0.17.1
# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1