Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions homeassistant/components/sensirion_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from .const import DOMAIN
from .models import SensirionBluetoothConfigEntry

PLATFORMS: list[Platform] = [Platform.SENSOR]

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(
hass: HomeAssistant, entry: SensirionBluetoothConfigEntry
) -> bool:
"""Set up Sensirion BLE device from a config entry."""
address = entry.unique_id
assert address is not None
data = SensirionBluetoothDeviceData()
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.ACTIVE,
update_method=data.update,
)
entry.runtime_data = coordinator = PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.ACTIVE,
update_method=data.update,
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(
Expand All @@ -42,7 +42,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
8 changes: 8 additions & 0 deletions homeassistant/components/sensirion_ble/models.py
Comment thread
mib1185 marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Models for the sensirion_ble integration."""

from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothProcessorCoordinator,
)
from homeassistant.config_entries import ConfigEntry

type SensirionBluetoothConfigEntry = ConfigEntry[PassiveBluetoothProcessorCoordinator]
12 changes: 3 additions & 9 deletions homeassistant/components/sensirion_ble/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
Units,
)

from homeassistant import config_entries
from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothDataProcessor,
PassiveBluetoothDataUpdate,
PassiveBluetoothEntityKey,
PassiveBluetoothProcessorCoordinator,
PassiveBluetoothProcessorEntity,
)
from homeassistant.components.sensor import (
Expand All @@ -31,7 +29,7 @@
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info

from .const import DOMAIN
from .models import SensirionBluetoothConfigEntry

SENSOR_DESCRIPTIONS: dict[
tuple[SSDSensorDeviceClass, Units | None], SensorEntityDescription
Expand Down Expand Up @@ -103,15 +101,11 @@ def sensor_update_to_bluetooth_data_update(

async def async_setup_entry(
hass: HomeAssistant,
entry: config_entries.ConfigEntry,
entry: SensirionBluetoothConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the Sensirion BLE sensors."""
# Uses legacy hass.data[DOMAIN] pattern
# pylint: disable-next=hass-use-runtime-data
coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
entry.entry_id
]
coordinator = entry.runtime_data
processor = PassiveBluetoothDataProcessor(sensor_update_to_bluetooth_data_update)
entry.async_on_unload(
processor.async_add_entities_listener(
Expand Down