mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add support for switchbot contact/door sensor (#75730)
This commit is contained in:
parent
7d895c79e8
commit
e6802f4f7e
@ -19,6 +19,7 @@ from homeassistant.helpers import device_registry as dr
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_BOT,
|
ATTR_BOT,
|
||||||
|
ATTR_CONTACT,
|
||||||
ATTR_CURTAIN,
|
ATTR_CURTAIN,
|
||||||
ATTR_HYGROMETER,
|
ATTR_HYGROMETER,
|
||||||
CONF_RETRY_COUNT,
|
CONF_RETRY_COUNT,
|
||||||
@ -31,6 +32,7 @@ PLATFORMS_BY_TYPE = {
|
|||||||
ATTR_BOT: [Platform.SWITCH, Platform.SENSOR],
|
ATTR_BOT: [Platform.SWITCH, Platform.SENSOR],
|
||||||
ATTR_CURTAIN: [Platform.COVER, Platform.BINARY_SENSOR, Platform.SENSOR],
|
ATTR_CURTAIN: [Platform.COVER, Platform.BINARY_SENSOR, Platform.SENSOR],
|
||||||
ATTR_HYGROMETER: [Platform.SENSOR],
|
ATTR_HYGROMETER: [Platform.SENSOR],
|
||||||
|
ATTR_CONTACT: [Platform.BINARY_SENSOR, Platform.SENSOR],
|
||||||
}
|
}
|
||||||
CLASS_BY_DEVICE = {
|
CLASS_BY_DEVICE = {
|
||||||
ATTR_CURTAIN: switchbot.SwitchbotCurtain,
|
ATTR_CURTAIN: switchbot.SwitchbotCurtain,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
@ -20,8 +21,30 @@ PARALLEL_UPDATES = 1
|
|||||||
BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
|
BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
|
||||||
"calibration": BinarySensorEntityDescription(
|
"calibration": BinarySensorEntityDescription(
|
||||||
key="calibration",
|
key="calibration",
|
||||||
|
name="Calibration",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
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):
|
class SwitchBotBinarySensor(SwitchbotEntity, BinarySensorEntity):
|
||||||
"""Representation of a Switchbot binary sensor."""
|
"""Representation of a Switchbot binary sensor."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: SwitchbotDataUpdateCoordinator,
|
coordinator: SwitchbotDataUpdateCoordinator,
|
||||||
@ -62,8 +87,8 @@ class SwitchBotBinarySensor(SwitchbotEntity, BinarySensorEntity):
|
|||||||
super().__init__(coordinator, unique_id, mac, name=switchbot_name)
|
super().__init__(coordinator, unique_id, mac, name=switchbot_name)
|
||||||
self._sensor = binary_sensor
|
self._sensor = binary_sensor
|
||||||
self._attr_unique_id = f"{unique_id}-{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.entity_description = BINARY_SENSOR_TYPES[binary_sensor]
|
||||||
|
self._attr_name = self.entity_description.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
|
@ -6,11 +6,13 @@ MANUFACTURER = "switchbot"
|
|||||||
ATTR_BOT = "bot"
|
ATTR_BOT = "bot"
|
||||||
ATTR_CURTAIN = "curtain"
|
ATTR_CURTAIN = "curtain"
|
||||||
ATTR_HYGROMETER = "hygrometer"
|
ATTR_HYGROMETER = "hygrometer"
|
||||||
|
ATTR_CONTACT = "contact"
|
||||||
DEFAULT_NAME = "Switchbot"
|
DEFAULT_NAME = "Switchbot"
|
||||||
SUPPORTED_MODEL_TYPES = {
|
SUPPORTED_MODEL_TYPES = {
|
||||||
"WoHand": ATTR_BOT,
|
"WoHand": ATTR_BOT,
|
||||||
"WoCurtain": ATTR_CURTAIN,
|
"WoCurtain": ATTR_CURTAIN,
|
||||||
"WoSensorTH": ATTR_HYGROMETER,
|
"WoSensorTH": ATTR_HYGROMETER,
|
||||||
|
"WoContact": ATTR_CONTACT,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Config Defaults
|
# Config Defaults
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "switchbot",
|
"domain": "switchbot",
|
||||||
"name": "SwitchBot",
|
"name": "SwitchBot",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/switchbot",
|
"documentation": "https://www.home-assistant.io/integrations/switchbot",
|
||||||
"requirements": ["PySwitchbot==0.15.1"],
|
"requirements": ["PySwitchbot==0.15.2"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": ["bluetooth"],
|
"dependencies": ["bluetooth"],
|
||||||
"codeowners": ["@bdraco", "@danielhiversen", "@RenierM26", "@murtas"],
|
"codeowners": ["@bdraco", "@danielhiversen", "@RenierM26", "@murtas"],
|
||||||
|
@ -5,6 +5,7 @@ from homeassistant.components.sensor import (
|
|||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -36,21 +37,25 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
|
|||||||
key="battery",
|
key="battery",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=SensorDeviceClass.BATTERY,
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
"lightLevel": SensorEntityDescription(
|
"lightLevel": SensorEntityDescription(
|
||||||
key="lightLevel",
|
key="lightLevel",
|
||||||
native_unit_of_measurement="Level",
|
native_unit_of_measurement="Level",
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
),
|
),
|
||||||
"humidity": SensorEntityDescription(
|
"humidity": SensorEntityDescription(
|
||||||
key="humidity",
|
key="humidity",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
),
|
),
|
||||||
"temperature": SensorEntityDescription(
|
"temperature": SensorEntityDescription(
|
||||||
key="temperature",
|
key="temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ PyRMVtransport==0.3.3
|
|||||||
PySocks==1.7.1
|
PySocks==1.7.1
|
||||||
|
|
||||||
# homeassistant.components.switchbot
|
# homeassistant.components.switchbot
|
||||||
PySwitchbot==0.15.1
|
PySwitchbot==0.15.2
|
||||||
|
|
||||||
# homeassistant.components.transport_nsw
|
# homeassistant.components.transport_nsw
|
||||||
PyTransportNSW==0.1.1
|
PyTransportNSW==0.1.1
|
||||||
|
@ -33,7 +33,7 @@ PyRMVtransport==0.3.3
|
|||||||
PySocks==1.7.1
|
PySocks==1.7.1
|
||||||
|
|
||||||
# homeassistant.components.switchbot
|
# homeassistant.components.switchbot
|
||||||
PySwitchbot==0.15.1
|
PySwitchbot==0.15.2
|
||||||
|
|
||||||
# homeassistant.components.transport_nsw
|
# homeassistant.components.transport_nsw
|
||||||
PyTransportNSW==0.1.1
|
PyTransportNSW==0.1.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user