diff --git a/homeassistant/components/switchbot/coordinator.py b/homeassistant/components/switchbot/coordinator.py index 103e9d67c58..94018c1b46b 100644 --- a/homeassistant/components/switchbot/coordinator.py +++ b/homeassistant/components/switchbot/coordinator.py @@ -69,13 +69,16 @@ class SwitchbotDataUpdateCoordinator(PassiveBluetoothDataUpdateCoordinator): change: bluetooth.BluetoothChange, ) -> None: """Handle a Bluetooth event.""" + self.ble_device = service_info.device if adv := switchbot.parse_advertisement_data( service_info.device, service_info.advertisement ): - self.data = flatten_sensors_data(adv.data) if "modelName" in self.data: self._ready_event.set() _LOGGER.debug("%s: Switchbot data: %s", self.ble_device.address, self.data) + if not self.device.advertisement_changed(adv): + return + self.data = flatten_sensors_data(adv.data) self.device.update_from_advertisement(adv) super()._async_handle_bluetooth_event(service_info, change) diff --git a/homeassistant/components/switchbot/manifest.json b/homeassistant/components/switchbot/manifest.json index f322734ba54..e311295e52c 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.18.27"], + "requirements": ["PySwitchbot==0.19.0"], "config_flow": true, "dependencies": ["bluetooth"], "codeowners": [ diff --git a/homeassistant/components/switchbot/sensor.py b/homeassistant/components/switchbot/sensor.py index 886da1051b7..9658c1ed9c8 100644 --- a/homeassistant/components/switchbot/sensor.py +++ b/homeassistant/components/switchbot/sensor.py @@ -71,14 +71,16 @@ async def async_setup_entry( ) -> None: """Set up Switchbot sensor based on a config entry.""" coordinator: SwitchbotDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id] - async_add_entities( + entities = [ SwitchBotSensor( coordinator, sensor, ) for sensor in coordinator.data["data"] if sensor in SENSOR_TYPES - ) + ] + entities.append(SwitchbotRSSISensor(coordinator, "rssi")) + async_add_entities(entities) class SwitchBotSensor(SwitchbotEntity, SensorEntity): @@ -98,6 +100,15 @@ class SwitchBotSensor(SwitchbotEntity, SensorEntity): self.entity_description = SENSOR_TYPES[sensor] @property - def native_value(self) -> str: + def native_value(self) -> str | int: """Return the state of the sensor.""" return self.data["data"][self._sensor] + + +class SwitchbotRSSISensor(SwitchBotSensor): + """Representation of a Switchbot RSSI sensor.""" + + @property + def native_value(self) -> str | int: + """Return the state of the sensor.""" + return self.coordinator.ble_device.rssi diff --git a/requirements_all.txt b/requirements_all.txt index e516fc66736..6853f91defb 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.18.27 +PySwitchbot==0.19.0 # homeassistant.components.transport_nsw PyTransportNSW==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c182079c026..c58ddd1e686 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.18.27 +PySwitchbot==0.19.0 # homeassistant.components.transport_nsw PyTransportNSW==0.1.1