ESPHome binary sensor representing assist pipeline running (#91406)

* ESPHome binary sensor representing assist pipeline running

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* Rename to call active
Simplify with attrs a little

* Load binary sensor if voice assistant on device

* Add some tests

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Jesse Hills
2023-04-18 11:52:37 +12:00
committed by GitHub
parent 28652345bd
commit 8d201b205f
6 changed files with 151 additions and 2 deletions

View File

@@ -6,13 +6,15 @@ from aioesphomeapi import BinarySensorInfo, BinarySensorState
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.enum import try_parse_enum
from . import EsphomeEntity, platform_async_setup_entry
from . import EsphomeAssistEntity, EsphomeEntity, platform_async_setup_entry
from .domain_data import DomainData
async def async_setup_entry(
@@ -29,6 +31,11 @@ async def async_setup_entry(
state_type=BinarySensorState,
)
entry_data = DomainData.get(hass).get_entry_data(entry)
assert entry_data.device_info is not None
if entry_data.device_info.voice_assistant_version:
async_add_entities([EsphomeCallActiveBinarySensor(entry_data)])
class EsphomeBinarySensor(
EsphomeEntity[BinarySensorInfo, BinarySensorState], BinarySensorEntity
@@ -59,3 +66,17 @@ class EsphomeBinarySensor(
if self._static_info.is_status_binary_sensor:
return True
return super().available
class EsphomeCallActiveBinarySensor(EsphomeAssistEntity, BinarySensorEntity):
"""A binary sensor implementation for ESPHome for use with assist_pipeline."""
entity_description = BinarySensorEntityDescription(
key="call_active",
translation_key="call_active",
)
@property
def is_on(self) -> bool | None:
"""Return true if the binary sensor is on."""
return self._entry_data.assist_pipeline_state