mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Update sharkiq to use CoordinatorEntity (#39427)
* Update sharkiq to use CoordinatorEntity Fix pylint * revert
This commit is contained in:
parent
70c241b51b
commit
0a389a4651
@ -23,6 +23,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
StateVacuumEntity,
|
StateVacuumEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import DOMAIN, SHARK
|
from .const import DOMAIN, SHARK
|
||||||
from .update_coordinator import SharkIqUpdateCoordinator
|
from .update_coordinator import SharkIqUpdateCoordinator
|
||||||
@ -65,23 +66,18 @@ ATTR_RECHARGE_RESUME = "recharge_and_resume"
|
|||||||
ATTR_RSSI = "rssi"
|
ATTR_RSSI = "rssi"
|
||||||
|
|
||||||
|
|
||||||
class SharkVacuumEntity(StateVacuumEntity):
|
class SharkVacuumEntity(CoordinatorEntity, StateVacuumEntity):
|
||||||
"""Shark IQ vacuum entity."""
|
"""Shark IQ vacuum entity."""
|
||||||
|
|
||||||
def __init__(self, sharkiq: SharkIqVacuum, coordinator: SharkIqUpdateCoordinator):
|
def __init__(self, sharkiq: SharkIqVacuum, coordinator: SharkIqUpdateCoordinator):
|
||||||
"""Create a new SharkVacuumEntity."""
|
"""Create a new SharkVacuumEntity."""
|
||||||
|
super().__init__(coordinator)
|
||||||
if sharkiq.serial_number not in coordinator.shark_vacs:
|
if sharkiq.serial_number not in coordinator.shark_vacs:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Shark IQ robot {sharkiq.serial_number} is not known to the coordinator"
|
f"Shark IQ robot {sharkiq.serial_number} is not known to the coordinator"
|
||||||
)
|
)
|
||||||
self.coordinator = coordinator
|
|
||||||
self.sharkiq = sharkiq
|
self.sharkiq = sharkiq
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Don't poll this entity. Polling is done via the coordinator."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
def clean_spot(self, **kwargs):
|
def clean_spot(self, **kwargs):
|
||||||
"""Clean a spot. Not yet implemented."""
|
"""Clean a spot. Not yet implemented."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
@ -189,16 +185,6 @@ class SharkVacuumEntity(StateVacuumEntity):
|
|||||||
"""Get the current battery level."""
|
"""Get the current battery level."""
|
||||||
return self.sharkiq.get_property_value(Properties.BATTERY_CAPACITY)
|
return self.sharkiq.get_property_value(Properties.BATTERY_CAPACITY)
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Update the known properties asynchronously."""
|
|
||||||
await self.coordinator.async_request_refresh()
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
|
||||||
"""Connect to dispatcher listening for entity data notifications."""
|
|
||||||
self.async_on_remove(
|
|
||||||
self.coordinator.async_add_listener(self.async_write_ha_state)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_return_to_base(self, **kwargs):
|
async def async_return_to_base(self, **kwargs):
|
||||||
"""Have the device return to base."""
|
"""Have the device return to base."""
|
||||||
await self.sharkiq.async_set_operating_mode(OperatingModes.RETURN)
|
await self.sharkiq.async_set_operating_mode(OperatingModes.RETURN)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user