ha-hunterbtt

Home Assistant integration for Hunter BTT
git clone https://git.stephank.nl/ha-hunterbtt
Log | Files | Refs | README | LICENSE | ZIP

binary_sensor.py (1554B)


      1 """Binary sensors for Hunter BTT."""
      2 
      3 from typing import override
      4 
      5 from homeassistant.components.binary_sensor import BinarySensorEntity
      6 from homeassistant.core import HomeAssistant
      7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
      8 
      9 from .coordinator import HunterBTTConfigEntry, HunterBTTCoordinator
     10 from .entity import HunterBTTEntity
     11 
     12 
     13 async def async_setup_entry(
     14     _hass: HomeAssistant,
     15     entry: HunterBTTConfigEntry,
     16     async_add_entities: AddEntitiesCallback,
     17 ) -> None:
     18     """Set up Hunter BTT binary sensors."""
     19     coordinator = entry.runtime_data
     20     channel_count = coordinator.data.state.channel_count or 1
     21     async_add_entities(
     22         [
     23             HunterBTTWateringSensor(coordinator, channel)
     24             for channel in range(1, channel_count + 1)
     25         ]
     26     )
     27 
     28 
     29 class HunterBTTWateringSensor(HunterBTTEntity, BinarySensorEntity):
     30     """Report whether the physical BTT output is watering."""
     31 
     32     _attr_translation_key = "watering"
     33 
     34     def __init__(self, coordinator: HunterBTTCoordinator, channel: int) -> None:
     35         """Initialize the watering sensor."""
     36         super().__init__(coordinator, f"zone_{channel}_watering")
     37         self._channel = channel
     38 
     39     @property
     40     @override
     41     def is_on(self) -> bool:
     42         """Return the physical zone's FF82 state."""
     43         if self.coordinator.data is None:
     44             return False
     45         if self._channel == 1:
     46             return bool(self.coordinator.data.state.zone1_is_watering)
     47         return bool(self.coordinator.data.state.zone2_is_watering)