diff --git a/homeassistant/components/switchbot/__init__.py b/homeassistant/components/switchbot/__init__.py index 46d6755553a..42ca0856b02 100644 --- a/homeassistant/components/switchbot/__init__.py +++ b/homeassistant/components/switchbot/__init__.py @@ -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, diff --git a/homeassistant/components/switchbot/binary_sensor.py b/homeassistant/components/switchbot/binary_sensor.py index d644f603697..4da4ed531b0 100644 --- a/homeassistant/components/switchbot/binary_sensor.py +++ b/homeassistant/components/switchbot/binary_sensor.py @@ -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: diff --git a/homeassistant/components/switchbot/const.py b/homeassistant/components/switchbot/const.py index e9602a19048..dc5abc139e6 100644 --- a/homeassistant/components/switchbot/const.py +++ b/homeassistant/components/switchbot/const.py @@ -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 diff --git a/homeassistant/components/switchbot/manifest.json b/homeassistant/components/switchbot/manifest.json index 3bccbb4f674..d6acb69431e 100644 --- a/homeassistant/components/switchbot/manifest.json +++ b/homeassistant/components/switchbot/manifest.json @@ -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"], diff --git a/homeassistant/components/switchbot/sensor.py b/homeassistant/components/switchbot/sensor.py index 25863a57df5..f796ea05e7b 100644 --- a/homeassistant/components/switchbot/sensor.py +++ b/homeassistant/components/switchbot/sensor.py @@ -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, ), } diff --git a/requirements_all.txt b/requirements_all.txt index c57f5c350af..2fa86ae9053 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b0773fc089a..bd79723fc79 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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