1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-30 19:26:31 +01:00
Files
core/homeassistant/components/roomba/binary_sensor.py
T
epenet a560967861 Use runtime_data in roomba integration (#167667)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 12:13:44 +02:00

45 lines
1.4 KiB
Python

"""Roomba binary sensor entities."""
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import roomba_reported_state
from .entity import IRobotEntity
from .models import RoombaConfigEntry
async def async_setup_entry(
hass: HomeAssistant,
config_entry: RoombaConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the iRobot Roomba vacuum cleaner."""
domain_data = config_entry.runtime_data
roomba = domain_data.roomba
blid = domain_data.blid
status = roomba_reported_state(roomba).get("bin", {})
if "full" in status:
roomba_vac = RoombaBinStatus(roomba, blid)
async_add_entities([roomba_vac])
class RoombaBinStatus(IRobotEntity, BinarySensorEntity):
"""Class to hold Roomba Sensor basic info."""
_attr_translation_key = "bin_full"
@property
def unique_id(self):
"""Return the ID of this sensor."""
return f"bin_{self._blid}"
@property
def is_on(self) -> bool:
"""Return the state of the sensor."""
return roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
def new_state_filter(self, new_state):
"""Filter the new state."""
return "bin" in new_state