Allow data from un-connectable sources in fjäråskupan (#77236)
parent
ff3d3088ee
commit
4185a70882
|
@ -22,6 +22,7 @@ from homeassistant.components.bluetooth import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
|
@ -33,6 +34,11 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||
|
||||
from .const import DISPATCH_DETECTION, DOMAIN
|
||||
|
||||
|
||||
class UnableToConnect(HomeAssistantError):
|
||||
"""Exception to indicate that we can not connect to device."""
|
||||
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.FAN,
|
||||
|
@ -75,28 +81,39 @@ class Coordinator(DataUpdateCoordinator[State]):
|
|||
async def _async_update_data(self) -> State:
|
||||
"""Handle an explicit update request."""
|
||||
if self._refresh_was_scheduled:
|
||||
if async_address_present(self.hass, self.device.address):
|
||||
if async_address_present(self.hass, self.device.address, False):
|
||||
return self.device.state
|
||||
raise UpdateFailed(
|
||||
"No data received within schedule, and device is no longer present"
|
||||
)
|
||||
|
||||
await self.device.update()
|
||||
if (
|
||||
ble_device := async_ble_device_from_address(
|
||||
self.hass, self.device.address, True
|
||||
)
|
||||
) is None:
|
||||
raise UpdateFailed("No connectable path to device")
|
||||
async with self.device.connect(ble_device) as device:
|
||||
await device.update()
|
||||
return self.device.state
|
||||
|
||||
def detection_callback(self, service_info: BluetoothServiceInfoBleak) -> None:
|
||||
"""Handle a new announcement of data."""
|
||||
self.device.device = service_info.device
|
||||
self.device.detection_callback(service_info.device, service_info.advertisement)
|
||||
self.async_set_updated_data(self.device.state)
|
||||
|
||||
@asynccontextmanager
|
||||
async def async_connect_and_update(self) -> AsyncIterator[Device]:
|
||||
"""Provide an up to date device for use during connections."""
|
||||
if ble_device := async_ble_device_from_address(self.hass, self.device.address):
|
||||
self.device.device = ble_device
|
||||
async with self.device:
|
||||
yield self.device
|
||||
if (
|
||||
ble_device := async_ble_device_from_address(
|
||||
self.hass, self.device.address, True
|
||||
)
|
||||
) is None:
|
||||
raise UnableToConnect("No connectable path to device")
|
||||
|
||||
async with self.device.connect(ble_device) as device:
|
||||
yield device
|
||||
|
||||
self.async_set_updated_data(self.device.state)
|
||||
|
||||
|
@ -126,7 +143,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
else:
|
||||
_LOGGER.debug("Detected: %s", service_info)
|
||||
|
||||
device = Device(service_info.device)
|
||||
device = Device(service_info.device.address)
|
||||
device_info = DeviceInfo(
|
||||
connections={(dr.CONNECTION_BLUETOOTH, service_info.address)},
|
||||
identifiers={(DOMAIN, service_info.address)},
|
||||
|
@ -149,6 +166,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
BluetoothCallbackMatcher(
|
||||
manufacturer_id=20296,
|
||||
manufacturer_data_start=[79, 68, 70, 74, 65, 82],
|
||||
connectable=False,
|
||||
),
|
||||
BluetoothScanningMode.ACTIVE,
|
||||
)
|
||||
|
|
|
@ -3,13 +3,14 @@
|
|||
"name": "Fj\u00e4r\u00e5skupan",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/fjaraskupan",
|
||||
"requirements": ["fjaraskupan==1.0.2"],
|
||||
"requirements": ["fjaraskupan==2.0.0"],
|
||||
"codeowners": ["@elupus"],
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["bleak", "fjaraskupan"],
|
||||
"dependencies": ["bluetooth"],
|
||||
"bluetooth": [
|
||||
{
|
||||
"connectable": false,
|
||||
"manufacturer_id": 20296,
|
||||
"manufacturer_data_start": [79, 68, 70, 74, 65, 82]
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ BLUETOOTH: list[dict[str, bool | str | int | list[int]]] = [
|
|||
},
|
||||
{
|
||||
"domain": "fjaraskupan",
|
||||
"connectable": False,
|
||||
"manufacturer_id": 20296,
|
||||
"manufacturer_data_start": [
|
||||
79,
|
||||
|
|
|
@ -670,7 +670,7 @@ fivem-api==0.1.2
|
|||
fixerio==1.0.0a0
|
||||
|
||||
# homeassistant.components.fjaraskupan
|
||||
fjaraskupan==1.0.2
|
||||
fjaraskupan==2.0.0
|
||||
|
||||
# homeassistant.components.flipr
|
||||
flipr-api==1.4.2
|
||||
|
|
|
@ -489,7 +489,7 @@ file-read-backwards==2.0.0
|
|||
fivem-api==0.1.2
|
||||
|
||||
# homeassistant.components.fjaraskupan
|
||||
fjaraskupan==1.0.2
|
||||
fjaraskupan==2.0.0
|
||||
|
||||
# homeassistant.components.flipr
|
||||
flipr-api==1.4.2
|
||||
|
|
Loading…
Reference in New Issue