Skip to content

Commit

Permalink
Bump pySwitchbot to 0.20.0 for bleak 0.19 changes (home-assistant#80389)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 16, 2022
1 parent 4060099 commit bbe63bc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 0 additions & 2 deletions homeassistant/components/switchbot/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(
self.device_name = device_name
self.base_unique_id = base_unique_id
self.model = model
self.service_info: bluetooth.BluetoothServiceInfoBleak | None = None
self._ready_event = asyncio.Event()

@callback
Expand All @@ -71,7 +70,6 @@ def _async_handle_bluetooth_event(
) -> None:
"""Handle a Bluetooth event."""
self.ble_device = service_info.device
self.service_info = service_info
if adv := switchbot.parse_advertisement_data(
service_info.device, service_info.advertisement
):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switchbot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "switchbot",
"name": "SwitchBot",
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"requirements": ["PySwitchbot==0.19.15"],
"requirements": ["PySwitchbot==0.20.0"],
"config_flow": true,
"dependencies": ["bluetooth"],
"codeowners": [
Expand Down
16 changes: 12 additions & 4 deletions homeassistant/components/switchbot/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Support for SwitchBot sensors."""
from __future__ import annotations

from homeassistant.components.bluetooth import async_last_service_info
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
Expand Down Expand Up @@ -106,7 +107,7 @@ def __init__(
self.entity_description = SENSOR_TYPES[sensor]

@property
def native_value(self) -> str | int:
def native_value(self) -> str | int | None:
"""Return the state of the sensor."""
return self.data["data"][self._sensor]

Expand All @@ -115,7 +116,14 @@ class SwitchbotRSSISensor(SwitchBotSensor):
"""Representation of a Switchbot RSSI sensor."""

@property
def native_value(self) -> str | int:
def native_value(self) -> str | int | None:
"""Return the state of the sensor."""
assert self.coordinator.service_info is not None
return self.coordinator.service_info.rssi
# Switchbot supports both connectable and non-connectable devices
# so we need to request the rssi value based on the connectable instead
# of the nearest scanner since that is the RSSI that matters for controlling
# the device.
if service_info := async_last_service_info(
self.hass, self._address, self.coordinator.connectable
):
return service_info.rssi
return None
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1

# homeassistant.components.switchbot
PySwitchbot==0.19.15
PySwitchbot==0.20.0

# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PyRMVtransport==0.3.3
PySocks==1.7.1

# homeassistant.components.switchbot
PySwitchbot==0.19.15
PySwitchbot==0.20.0

# homeassistant.components.transport_nsw
PyTransportNSW==0.1.1
Expand Down

0 comments on commit bbe63bc

Please sign in to comment.