mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-08 22:07:06 +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,
|
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:
|
def query(self) -> dict:
|
||||||
"""Query to execute during the update cycle."""
|
"""Query to execute during the update cycle."""
|
||||||
return {"getVacStatus": None}
|
return {"getVacStatus": None, "getBatteryInfo": None}
|
||||||
|
|
||||||
async def start(self) -> dict:
|
async def start(self) -> dict:
|
||||||
"""Start cleaning."""
|
"""Start cleaning."""
|
||||||
@ -123,13 +136,23 @@ class Vacuum(SmartModule):
|
|||||||
"""Return home / pause returning."""
|
"""Return home / pause returning."""
|
||||||
return await self.call("setSwitchCharge", {"switch_charge": enabled})
|
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
|
@property
|
||||||
def status(self) -> Status:
|
def status(self) -> Status:
|
||||||
"""Return current status."""
|
"""Return current status."""
|
||||||
if self.data.get("err_status"):
|
if self._vac_status.get("err_status"):
|
||||||
return Status.Error
|
return Status.Error
|
||||||
|
|
||||||
status_code = self.data["status"]
|
status_code = self._vac_status["status"]
|
||||||
try:
|
try:
|
||||||
return Status(status_code)
|
return Status(status_code)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
Loading…
Reference in New Issue
Block a user