mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Add battery level
This commit is contained in:
parent
09450b5462
commit
8ff6172c30
@ -80,10 +80,23 @@ class Vacuum(SmartModule):
|
||||
type=Feature.Type.Sensor,
|
||||
)
|
||||
)
|
||||
self._add_feature(
|
||||
Feature(
|
||||
self._device,
|
||||
"battery_level",
|
||||
"Battery level",
|
||||
container=self,
|
||||
attribute_getter="battery",
|
||||
icon="mdi:battery",
|
||||
unit_getter=lambda: "%",
|
||||
category=Feature.Category.Info,
|
||||
type=Feature.Type.Sensor,
|
||||
)
|
||||
)
|
||||
|
||||
def query(self) -> dict:
|
||||
"""Query to execute during the update cycle."""
|
||||
return {"getVacStatus": None}
|
||||
return {"getVacStatus": None, "getBatteryInfo": None}
|
||||
|
||||
async def start(self) -> dict:
|
||||
"""Start cleaning."""
|
||||
@ -123,13 +136,23 @@ class Vacuum(SmartModule):
|
||||
"""Return home / pause returning."""
|
||||
return await self.call("setSwitchCharge", {"switch_charge": enabled})
|
||||
|
||||
@property
|
||||
def battery(self) -> int:
|
||||
"""Return battery level."""
|
||||
return self.data["getBatteryInfo"]["battery_percentage"]
|
||||
|
||||
@property
|
||||
def _vac_status(self) -> dict:
|
||||
"""Return vac status container."""
|
||||
return self.data["getVacStatus"]
|
||||
|
||||
@property
|
||||
def status(self) -> Status:
|
||||
"""Return current status."""
|
||||
if self.data.get("err_status"):
|
||||
if self._vac_status.get("err_status"):
|
||||
return Status.Error
|
||||
|
||||
status_code = self.data["status"]
|
||||
status_code = self._vac_status["status"]
|
||||
try:
|
||||
return Status(status_code)
|
||||
except ValueError:
|
||||
|
Loading…
Reference in New Issue
Block a user