Add Sure Petcare Felaqua device (#56823)
* add a SurePetcareSensor
* add the felaqua sensor
* add felaqua battery test
* fix felaqua product_id
* actually add a felaqua sensor 😅
* remove superclass
pull/57367/head
parent
6d0da631bf
commit
fe065b2de8
|
@ -2,13 +2,20 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import cast
|
||||
|
||||
from surepy.entities import SurepyEntity
|
||||
from surepy.entities.devices import Felaqua as SurepyFelaqua
|
||||
from surepy.enums import EntityType
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_VOLTAGE, DEVICE_CLASS_BATTERY, PERCENTAGE
|
||||
from homeassistant.const import (
|
||||
ATTR_VOLTAGE,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
PERCENTAGE,
|
||||
VOLUME_MILLILITERS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -24,7 +31,7 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up Sure PetCare Flaps sensors."""
|
||||
|
||||
entities: list[SureBattery] = []
|
||||
entities: list[SurePetcareEntity] = []
|
||||
|
||||
coordinator: SurePetcareDataCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
|
@ -38,6 +45,9 @@ async def async_setup_entry(
|
|||
]:
|
||||
entities.append(SureBattery(surepy_entity.id, coordinator))
|
||||
|
||||
if surepy_entity.type == EntityType.FELAQUA:
|
||||
entities.append(Felaqua(surepy_entity.id, coordinator))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
@ -78,3 +88,27 @@ class SureBattery(SurePetcareEntity, SensorEntity):
|
|||
}
|
||||
else:
|
||||
self._attr_extra_state_attributes = {}
|
||||
|
||||
|
||||
class Felaqua(SurePetcareEntity, SensorEntity):
|
||||
"""Sure Petcare Felaqua."""
|
||||
|
||||
_attr_native_unit_of_measurement = VOLUME_MILLILITERS
|
||||
|
||||
def __init__(
|
||||
self, surepetcare_id: int, coordinator: SurePetcareDataCoordinator
|
||||
) -> None:
|
||||
"""Initialize a Sure Petcare Felaqua sensor."""
|
||||
super().__init__(surepetcare_id, coordinator)
|
||||
|
||||
surepy_entity: SurepyFelaqua = coordinator.data[surepetcare_id]
|
||||
|
||||
self._attr_name = self._device_name
|
||||
self._attr_unique_id = self._device_id
|
||||
self._attr_entity_picture = surepy_entity.icon
|
||||
|
||||
@callback
|
||||
def _update_attr(self, surepy_entity: SurepyEntity) -> None:
|
||||
"""Update the state."""
|
||||
surepy_entity = cast(SurepyFelaqua, surepy_entity)
|
||||
self._attr_native_value = surepy_entity.water_remaining
|
||||
|
|
|
@ -27,6 +27,19 @@ MOCK_FEEDER = {
|
|||
},
|
||||
}
|
||||
|
||||
MOCK_FELAQUA = {
|
||||
"id": 31337,
|
||||
"product_id": 8,
|
||||
"household_id": HOUSEHOLD_ID,
|
||||
"name": "Felaqua",
|
||||
"parent": {"product_id": 1, "id": HUB_ID},
|
||||
"status": {
|
||||
"battery": 6.4,
|
||||
"signal": {"device_rssi": 70, "hub_rssi": 65},
|
||||
"online": True,
|
||||
},
|
||||
}
|
||||
|
||||
MOCK_CAT_FLAP = {
|
||||
"id": 13579,
|
||||
"product_id": 6,
|
||||
|
@ -66,7 +79,7 @@ MOCK_PET = {
|
|||
}
|
||||
|
||||
MOCK_API_DATA = {
|
||||
"devices": [MOCK_HUB, MOCK_CAT_FLAP, MOCK_PET_FLAP, MOCK_FEEDER],
|
||||
"devices": [MOCK_HUB, MOCK_CAT_FLAP, MOCK_PET_FLAP, MOCK_FEEDER, MOCK_FELAQUA],
|
||||
"pets": [MOCK_PET],
|
||||
}
|
||||
|
||||
|
|
|
@ -3,12 +3,13 @@ from homeassistant.components.surepetcare.const import DOMAIN
|
|||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import HOUSEHOLD_ID, MOCK_CONFIG
|
||||
from . import HOUSEHOLD_ID, MOCK_CONFIG, MOCK_FELAQUA
|
||||
|
||||
EXPECTED_ENTITY_IDS = {
|
||||
"sensor.pet_flap_battery_level": f"{HOUSEHOLD_ID}-13576-battery",
|
||||
"sensor.cat_flap_battery_level": f"{HOUSEHOLD_ID}-13579-battery",
|
||||
"sensor.feeder_battery_level": f"{HOUSEHOLD_ID}-12345-battery",
|
||||
"sensor.felaqua_battery_level": f"{HOUSEHOLD_ID}-{MOCK_FELAQUA['id']}-battery",
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue