mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Add binary sensor platform to romy integration (#112998)
* wip * poc working, reworked to a binary sensor list * Update homeassistant/components/romy/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/romy/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/romy/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/romy/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/romy/binary_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * code review changes, adjust translation key names * code review clean up: removed unecessary RomyBinarySensorEntityDescription * code review changes: translation names * code review changes, put DeviceInfo into RomyEntity * code review change: change docked icon to type plug * code review change: move CoordinatorEntity to the base class * code review changes: sensors disabled per default * code review: icons.json added * code review changes: sensors enabled per default again * checkout main entity.py * type hinting changes * Update homeassistant/components/romy/binary_sensor.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
74cea2ecae
commit
220dc1f125
@ -1158,6 +1158,7 @@ omit =
|
|||||||
homeassistant/components/roborock/coordinator.py
|
homeassistant/components/roborock/coordinator.py
|
||||||
homeassistant/components/rocketchat/notify.py
|
homeassistant/components/rocketchat/notify.py
|
||||||
homeassistant/components/romy/__init__.py
|
homeassistant/components/romy/__init__.py
|
||||||
|
homeassistant/components/romy/binary_sensor.py
|
||||||
homeassistant/components/romy/coordinator.py
|
homeassistant/components/romy/coordinator.py
|
||||||
homeassistant/components/romy/entity.py
|
homeassistant/components/romy/entity.py
|
||||||
homeassistant/components/romy/vacuum.py
|
homeassistant/components/romy/vacuum.py
|
||||||
|
73
homeassistant/components/romy/binary_sensor.py
Normal file
73
homeassistant/components/romy/binary_sensor.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
"""Checking binary status values from your ROMY."""
|
||||||
|
|
||||||
|
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 .const import DOMAIN
|
||||||
|
from .coordinator import RomyVacuumCoordinator
|
||||||
|
from .entity import RomyEntity
|
||||||
|
|
||||||
|
BINARY_SENSORS: list[BinarySensorEntityDescription] = [
|
||||||
|
BinarySensorEntityDescription(
|
||||||
|
key="dustbin",
|
||||||
|
translation_key="dustbin_present",
|
||||||
|
),
|
||||||
|
BinarySensorEntityDescription(
|
||||||
|
key="dock",
|
||||||
|
translation_key="docked",
|
||||||
|
device_class=BinarySensorDeviceClass.PLUG,
|
||||||
|
),
|
||||||
|
BinarySensorEntityDescription(
|
||||||
|
key="water_tank",
|
||||||
|
translation_key="water_tank_present",
|
||||||
|
device_class=BinarySensorDeviceClass.MOISTURE,
|
||||||
|
),
|
||||||
|
BinarySensorEntityDescription(
|
||||||
|
key="water_tank_empty",
|
||||||
|
translation_key="water_tank_empty",
|
||||||
|
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up ROMY vacuum cleaner."""
|
||||||
|
|
||||||
|
coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
RomyBinarySensor(coordinator, entity_description)
|
||||||
|
for entity_description in BINARY_SENSORS
|
||||||
|
if entity_description.key in coordinator.romy.binary_sensors
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RomyBinarySensor(RomyEntity, BinarySensorEntity):
|
||||||
|
"""RomyBinarySensor Class."""
|
||||||
|
|
||||||
|
entity_description: BinarySensorEntityDescription
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: RomyVacuumCoordinator,
|
||||||
|
entity_description: BinarySensorEntityDescription,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize ROMYs StatusSensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self._attr_unique_id = f"{entity_description.key}_{self.romy.unique_id}"
|
||||||
|
self.entity_description = entity_description
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
"""Return the value of the sensor."""
|
||||||
|
return bool(self.romy.binary_sensors[self.entity_description.key])
|
@ -6,6 +6,6 @@ import logging
|
|||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
|
|
||||||
DOMAIN = "romy"
|
DOMAIN = "romy"
|
||||||
PLATFORMS = [Platform.VACUUM]
|
PLATFORMS = [Platform.BINARY_SENSOR, Platform.VACUUM]
|
||||||
UPDATE_INTERVAL = timedelta(seconds=5)
|
UPDATE_INTERVAL = timedelta(seconds=5)
|
||||||
LOGGER = logging.getLogger(__package__)
|
LOGGER = logging.getLogger(__package__)
|
||||||
|
20
homeassistant/components/romy/icons.json
Normal file
20
homeassistant/components/romy/icons.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"entity": {
|
||||||
|
"binary_sensor": {
|
||||||
|
"water_tank_empty": {
|
||||||
|
"default": "mdi:cup-outline",
|
||||||
|
"state": {
|
||||||
|
"off": "mdi:cup-water",
|
||||||
|
"on": "mdi:cup-outline"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dustbin_present": {
|
||||||
|
"default": "mdi:basket-check",
|
||||||
|
"state": {
|
||||||
|
"off": "mdi:basket-remove",
|
||||||
|
"on": "mdi:basket-check"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"binary_sensor": {
|
||||||
|
"dustbin_present": {
|
||||||
|
"name": "Dustbin present"
|
||||||
|
},
|
||||||
|
"docked": {
|
||||||
|
"name": "Robot docked"
|
||||||
|
},
|
||||||
|
"water_tank_present": {
|
||||||
|
"name": "Watertank present"
|
||||||
|
},
|
||||||
|
"water_tank_empty": {
|
||||||
|
"name": "Watertank empty"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user