Add support for switchbot contact/door sensor (#75730)

pull/75771/head
J. Nick Koston 2022-07-26 05:14:02 -10:00 committed by GitHub
parent 7d895c79e8
commit e6802f4f7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 4 deletions

View File

@ -19,6 +19,7 @@ from homeassistant.helpers import device_registry as dr
from .const import (
ATTR_BOT,
ATTR_CONTACT,
ATTR_CURTAIN,
ATTR_HYGROMETER,
CONF_RETRY_COUNT,
@ -31,6 +32,7 @@ PLATFORMS_BY_TYPE = {
ATTR_BOT: [Platform.SWITCH, Platform.SENSOR],
ATTR_CURTAIN: [Platform.COVER, Platform.BINARY_SENSOR, Platform.SENSOR],
ATTR_HYGROMETER: [Platform.SENSOR],
ATTR_CONTACT: [Platform.BINARY_SENSOR, Platform.SENSOR],
}
CLASS_BY_DEVICE = {
ATTR_CURTAIN: switchbot.SwitchbotCurtain,

View File

@ -2,6 +2,7 @@
from __future__ import annotations
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
@ -20,8 +21,30 @@ PARALLEL_UPDATES = 1
BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
"calibration": BinarySensorEntityDescription(
key="calibration",
name="Calibration",
entity_category=EntityCategory.DIAGNOSTIC,
),
"motion_detected": BinarySensorEntityDescription(
key="pir_state",
name="Motion detected",
device_class=BinarySensorDeviceClass.MOTION,
),
"contact_open": BinarySensorEntityDescription(
key="contact_open",
name="Door open",
device_class=BinarySensorDeviceClass.DOOR,
),
"contact_timeout": BinarySensorEntityDescription(
key="contact_timeout",
name="Door timeout",
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
),
"is_light": BinarySensorEntityDescription(
key="is_light",
name="Light",
device_class=BinarySensorDeviceClass.LIGHT,
),
}
@ -50,6 +73,8 @@ async def async_setup_entry(
class SwitchBotBinarySensor(SwitchbotEntity, BinarySensorEntity):
"""Representation of a Switchbot binary sensor."""
_attr_has_entity_name = True
def __init__(
self,
coordinator: SwitchbotDataUpdateCoordinator,
@ -62,8 +87,8 @@ class SwitchBotBinarySensor(SwitchbotEntity, BinarySensorEntity):
super().__init__(coordinator, unique_id, mac, name=switchbot_name)
self._sensor = binary_sensor
self._attr_unique_id = f"{unique_id}-{binary_sensor}"
self._attr_name = f"{switchbot_name} {binary_sensor.title()}"
self.entity_description = BINARY_SENSOR_TYPES[binary_sensor]
self._attr_name = self.entity_description.name
@property
def is_on(self) -> bool:

View File

@ -6,11 +6,13 @@ MANUFACTURER = "switchbot"
ATTR_BOT = "bot"
ATTR_CURTAIN = "curtain"
ATTR_HYGROMETER = "hygrometer"
ATTR_CONTACT = "contact"
DEFAULT_NAME = "Switchbot"
SUPPORTED_MODEL_TYPES = {
"WoHand": ATTR_BOT,
"WoCurtain": ATTR_CURTAIN,
"WoSensorTH": ATTR_HYGROMETER,
"WoContact": ATTR_CONTACT,
}
# Config Defaults

View File

@ -2,7 +2,7 @@
"domain": "switchbot",
"name": "SwitchBot",
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"requirements": ["PySwitchbot==0.15.1"],
"requirements": ["PySwitchbot==0.15.2"],
"config_flow": true,
"dependencies": ["bluetooth"],
"codeowners": ["@bdraco", "@danielhiversen", "@RenierM26", "@murtas"],

View File

@ -5,6 +5,7 @@ from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
@ -36,21 +37,25 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
key="battery",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
),
"lightLevel": SensorEntityDescription(
key="lightLevel",
native_unit_of_measurement="Level",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.ILLUMINANCE,
),
"humidity": SensorEntityDescription(
key="humidity",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.HUMIDITY,
),
"temperature": SensorEntityDescription(
key="temperature",
native_unit_of_measurement=TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
),
}

View File

@ -37,7 +37,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1
# homeassistant.components.switchbot
PySwitchbot==0.15.1
PySwitchbot==0.15.2
# 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.15.1
PySwitchbot==0.15.2
# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1