1 """Support for Medcom BLE radiation monitor sensors."""
3 from __future__
import annotations
7 from medcom_ble
import MedcomBleDevice
9 from homeassistant
import config_entries
12 SensorEntityDescription,
20 DataUpdateCoordinator,
23 from .const
import DOMAIN, UNIT_CPM
25 _LOGGER = logging.getLogger(__name__)
27 SENSORS_MAPPING_TEMPLATE: dict[str, SensorEntityDescription] = {
30 translation_key=
"cpm",
31 native_unit_of_measurement=UNIT_CPM,
32 state_class=SensorStateClass.MEASUREMENT,
40 async_add_entities: AddEntitiesCallback,
42 """Set up Medcom BLE radiation monitor sensors."""
44 coordinator: DataUpdateCoordinator[MedcomBleDevice] = hass.data[DOMAIN][
49 _LOGGER.debug(
"got sensors: %s", coordinator.data.sensors)
50 for sensor_type, sensor_value
in coordinator.data.sensors.items():
51 if sensor_type
not in SENSORS_MAPPING_TEMPLATE:
53 "Unknown sensor type detected: %s, %s",
59 MedcomSensor(coordinator, SENSORS_MAPPING_TEMPLATE[sensor_type])
66 CoordinatorEntity[DataUpdateCoordinator[MedcomBleDevice]], SensorEntity
68 """Medcom BLE radiation monitor sensors for the device."""
70 _attr_has_entity_name =
True
74 coordinator: DataUpdateCoordinator[MedcomBleDevice],
75 entity_description: SensorEntityDescription,
77 """Populate the medcom entity with relevant data."""
80 medcom_device = coordinator.data
82 name = medcom_device.name
83 if identifier := medcom_device.identifier:
84 name += f
" ({identifier})"
86 self.
_attr_unique_id_attr_unique_id = f
"{medcom_device.address}_{entity_description.key}"
91 medcom_device.address,
95 manufacturer=medcom_device.manufacturer,
96 hw_version=medcom_device.hw_version,
97 sw_version=medcom_device.sw_version,
98 model=medcom_device.model,
103 """Return the value reported by the sensor."""
None __init__(self, DataUpdateCoordinator[MedcomBleDevice] coordinator, SensorEntityDescription entity_description)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry entry, AddEntitiesCallback async_add_entities)