"""Diagnostic sensor exposing raw BT12 notify replies, undecoded. The notify channel (02060003) isn't reverse-engineered yet. This entity just surfaces whatever comes back after each command, in order to build up real data for that follow-on work -- don't assume the values mean anything yet. """ from __future__ import annotations from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN from .coordinator import Bt12Coordinator async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: coordinator: Bt12Coordinator = hass.data[DOMAIN][entry.entry_id] device_info = DeviceInfo( identifiers={(DOMAIN, entry.data["address"])}, name=entry.data.get("name", "BT12 Awning"), manufacturer="Carefree of Colorado", model="BT12", ) async_add_entities([Bt12LastNotification(coordinator, device_info)]) class Bt12LastNotification(SensorEntity): """Raw hex of the most recent GATT notification.""" _attr_has_entity_name = True _attr_name = "Last Notification" _attr_should_poll = False _attr_entity_category = EntityCategory.DIAGNOSTIC def __init__(self, coordinator: Bt12Coordinator, device_info: DeviceInfo) -> None: self._coordinator = coordinator self._attr_unique_id = f"{coordinator.address}_last_notification" self._attr_device_info = device_info @property def native_value(self) -> str | None: if not self._coordinator.last_notifications: return None return self._coordinator.last_notifications[-1] @property def extra_state_attributes(self) -> dict: return {"recent": self._coordinator.last_notifications} async def async_added_to_hass(self) -> None: self.async_on_remove(self._coordinator.async_add_listener(self._handle_update)) @callback def _handle_update(self) -> None: self.async_write_ha_state()