Add switches and sensors to Litter-Robot (#46942)
This commit is contained in:
parent
d4d68ebc64
commit
b8f7bc12ee
8 changed files with 242 additions and 23 deletions
54
homeassistant/components/litterrobot/sensor.py
Normal file
54
homeassistant/components/litterrobot/sensor.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""Support for Litter-Robot sensors."""
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .hub import LitterRobotEntity
|
||||
|
||||
WASTE_DRAWER = "Waste Drawer"
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up Litter-Robot sensors using config entry."""
|
||||
hub = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities = []
|
||||
for robot in hub.account.robots:
|
||||
entities.append(LitterRobotSensor(robot, WASTE_DRAWER, hub))
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class LitterRobotSensor(LitterRobotEntity, Entity):
|
||||
"""Litter-Robot sensors."""
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state."""
|
||||
return self.robot.waste_drawer_gauge
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return unit of measurement."""
|
||||
return PERCENTAGE
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend, if any."""
|
||||
if self.robot.waste_drawer_gauge <= 10:
|
||||
return "mdi:gauge-empty"
|
||||
if self.robot.waste_drawer_gauge < 50:
|
||||
return "mdi:gauge-low"
|
||||
if self.robot.waste_drawer_gauge <= 90:
|
||||
return "mdi:gauge"
|
||||
return "mdi:gauge-full"
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
return {
|
||||
"cycle_count": self.robot.cycle_count,
|
||||
"cycle_capacity": self.robot.cycle_capacity,
|
||||
"cycles_after_drawer_full": self.robot.cycles_after_drawer_full,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue