custom_components/omni_pca/ — six new platform modules wrapping the
v1.0 client surface. Every command method catches CommandFailedError
and re-raises HomeAssistantError so panel rejections (bad code, etc.)
become user-friendly HA errors instead of silent failures.
alarm_control_panel.py — OmniAreaAlarmPanel per discovered area.
Supports ARM_HOME (Day) / ARM_NIGHT / ARM_AWAY / ARM_VACATION /
ARM_CUSTOM_BYPASS (Day-Instant). State derives from area_status via
pure helpers.security_mode_to_alarm_state which handles arming-in-
progress, entry/exit timers, and active-alarm overrides.
light.py — OmniUnitLight per discovered unit (every unit; non-dimmable
units silently ignore brightness, no harm done). Brightness conversion
via helpers.omni_state_to_ha_brightness / ha_brightness_to_omni_percent
(Omni state byte: 0=off, 1=on, 100..200=brightness percent).
switch.py — OmniZoneBypassSwitch per binary zone. CONFIG entity_category;
pairs with the existing diagnostic 'zone bypassed' binary_sensor.
climate.py — OmniThermostatClimate per discovered thermostat.
Supports OFF / HEAT / COOL / HEAT_COOL hvac_modes; auto / on / diffuse
fan_modes; none / hold / vacation preset_modes. Single-setpoint and
range setpoint via TARGET_TEMPERATURE_RANGE. Fahrenheit native (Omni
panels are F-native; HA handles unit conversion downstream).
sensor.py — analog zones (temperature/humidity/power) + per-thermostat
diagnostic temp/humidity/outdoor sensors + OmniSystemModelSensor
+ OmniLastEventSensor (event_class + parsed event fields as attrs).
button.py — OmniPanelButton per discovered button macro. Programs not
yet exposed because the library lacks RequestProperties for Programs.
event.py — single OmniPanelEvent per panel relaying typed SystemEvents
via _trigger_event. event_types: zone_state_changed, unit_state_changed,
arming_changed, alarm_activated/cleared, ac_lost/restored,
battery_low/restored, user_macro_button, phone_line_dead/restored.
Automations key off platform: event + event_type filter.
helpers.py — extended with security_mode_to_alarm_state,
ARM_SERVICE_TO_SECURITY_MODE, omni_state_to_ha_brightness +
ha_brightness_to_omni_percent, omni/ha_{hvac,fan,hold} round-trips,
fahrenheit_to_omni_raw / celsius_to_omni_raw, analog_zone_device_class,
EVENT_TYPES tuple, event_type_for(class_name).
__init__.py — PLATFORMS extended to all 8 entity types.
scene.py intentionally NOT created — Omni 'scenes' are user-defined
button macros, already covered by the button platform. Documented in
README; revisit if/when the library gains scene-discovery opcodes.
tests/test_ha_helpers.py: +67 unit tests covering every new helper.
331 tests pass (was 264). Ruff clean across src/ tests/ custom_components/.
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
"""Event platform — surfaces the panel's typed push events as a single
|
|
``EventEntity`` per panel. The event_type attribute carries the kind of
|
|
event; event_data carries the parsed details. Trigger automations on
|
|
``platform: event`` filtering by event_type or event_data.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any, ClassVar
|
|
|
|
from homeassistant.components.event import EventEntity
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import OmniDataUpdateCoordinator
|
|
from .helpers import EVENT_TYPES, event_type_for
|
|
|
|
if TYPE_CHECKING:
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
coordinator: OmniDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities([OmniPanelEvent(coordinator)])
|
|
|
|
|
|
class OmniPanelEvent(
|
|
CoordinatorEntity[OmniDataUpdateCoordinator], EventEntity
|
|
):
|
|
"""One event entity per panel; relays every push event the coordinator sees."""
|
|
|
|
_attr_has_entity_name = True
|
|
_attr_event_types: ClassVar[list[str]] = list(EVENT_TYPES)
|
|
|
|
def __init__(self, coordinator: OmniDataUpdateCoordinator) -> None:
|
|
super().__init__(coordinator)
|
|
self._attr_unique_id = f"{coordinator.unique_id}-events"
|
|
self._attr_name = "Panel Events"
|
|
self._attr_device_info = coordinator.device_info
|
|
self._last_event_id: int | None = None
|
|
|
|
def _handle_coordinator_update(self) -> None:
|
|
ev = self.coordinator.data.last_event
|
|
if ev is None:
|
|
return
|
|
# Only fire when the event reference actually changed; the
|
|
# coordinator may push other state without a new event arriving.
|
|
ev_id = id(ev)
|
|
if ev_id == self._last_event_id:
|
|
return
|
|
self._last_event_id = ev_id
|
|
|
|
event_data: dict[str, Any] = {"event_class": type(ev).__name__}
|
|
for key in (
|
|
"zone_index", "unit_index", "area_index", "user_index",
|
|
"new_state", "new_mode", "alarm_type",
|
|
):
|
|
if hasattr(ev, key):
|
|
event_data[key] = getattr(ev, key)
|
|
|
|
self._trigger_event(event_type_for(type(ev).__name__), event_data)
|
|
self.async_write_ha_state()
|