async def detection_callback( ble_device: BLEDevice, advertisement_data: AdvertisementData) -> None: if not device_filter(ble_device, advertisement_data): return _LOGGER.debug("Detection: %s %s - %s", ble_device.name, ble_device, advertisement_data) data = state.devices.get(ble_device.address) if data: data.device.detection_callback(ble_device, advertisement_data) data.coordinator.async_set_updated_data(data.device.state) else: device = Device(ble_device) device.detection_callback(ble_device, advertisement_data) async def async_update_data(): """Handle an explicit update request.""" await device.update() return device.state coordinator: DataUpdateCoordinator[State] = DataUpdateCoordinator( hass, logger=_LOGGER, name="Fjaraskupan Updater", update_interval=timedelta(seconds=120), update_method=async_update_data, ) coordinator.async_set_updated_data(device.state) device_info: DeviceInfo = { "identifiers": {(DOMAIN, ble_device.address)}, "manufacturer": "Fjäråskupan", "name": "Fjäråskupan", } device_state = DeviceState(device, coordinator, device_info) state.devices[ble_device.address] = device_state async_dispatcher_send(hass, f"{DISPATCH_DETECTION}.{entry.entry_id}", device_state)
advertisement_data: AdvertisementData) -> None: if data := state.devices.get(ble_device.address): _LOGGER.debug("Update: %s %s - %s", ble_device.name, ble_device, advertisement_data) data.device.detection_callback(ble_device, advertisement_data) data.coordinator.async_set_updated_data(data.device.state) else: if not device_filter(ble_device, advertisement_data): return _LOGGER.debug("Detected: %s %s - %s", ble_device.name, ble_device, advertisement_data) device = Device(ble_device) device.detection_callback(ble_device, advertisement_data) async def async_update_data(): """Handle an explicit update request.""" await device.update() return device.state coordinator: DataUpdateCoordinator[State] = DataUpdateCoordinator( hass, logger=_LOGGER, name="Fjaraskupan Updater", update_interval=timedelta(seconds=120), update_method=async_update_data, ) coordinator.async_set_updated_data(device.state)