Files
lippert-onecontrol/custom_components/lippert_onecontrol/sensor.py
T
wesandClaude Opus 4.8 34155fd7f9 Add HA custom integration; fix bleak 3.x write-without-response regression
The OneControl panel's command characteristic is a streaming (Write Without
Response) endpoint. Bleak 3.x changed write_gatt_char to default to
write-with-response when the char advertises the "write" property, so every
command (incl. switch turn_on/off) got rejected by the panel with ATT 0x0E
(Unlikely Error), surfaced as BleakGATTProtocolError. Force response=False on
the command write (matching the auth key write) to restore control.

Also commits the productionized custom_components integration (config flow,
coordinator, switch/sensor/cover entities, key-seed TEA auth, COBS codec) and
the matching src/ RE client/COBS fixes (big-endian framing, table-driven CRC8,
status-event decoding) that were developed but never tracked.

Verified live on the campsite HAOS Pi: switch.exterior_lights / interior_lights
toggle the physical panel with no GATT error.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 06:41:14 -04:00

61 lines
2.2 KiB
Python

from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, SensorStateClass
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, UnitOfElectricPotential
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .coordinator import OneControlCoordinator
from .const import DOMAIN, TANK_DEVICES
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
coordinator: OneControlCoordinator = hass.data[DOMAIN][entry.entry_id]
entities: list[SensorEntity] = [
OneControlTankSensor(coordinator, device_id, name)
for device_id, name in TANK_DEVICES.items()
]
entities.append(OneControlBatterySensor(coordinator))
async_add_entities(entities)
class OneControlTankSensor(CoordinatorEntity, SensorEntity):
_attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class = SensorStateClass.MEASUREMENT
def __init__(self, coordinator: OneControlCoordinator, device_id: int, name: str) -> None:
super().__init__(coordinator)
self._device_id = device_id
self._attr_name = name
self._attr_unique_id = f"{coordinator.address}_tank_{device_id}"
@property
def native_value(self) -> int | None:
return self.coordinator.get_tank_level(self._device_id)
@property
def available(self) -> bool:
return self.coordinator.is_connected
class OneControlBatterySensor(CoordinatorEntity, SensorEntity):
_attr_native_unit_of_measurement = UnitOfElectricPotential.VOLT
_attr_device_class = SensorDeviceClass.VOLTAGE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_name = "Battery Voltage"
def __init__(self, coordinator: OneControlCoordinator) -> None:
super().__init__(coordinator)
self._attr_unique_id = f"{coordinator.address}_battery"
@property
def native_value(self) -> float | None:
v = self.coordinator.battery_voltage
return round(v, 2) if v is not None else None
@property
def available(self) -> bool:
return self.coordinator.is_connected