diff --git a/README.md b/README.md index cdbae5d..06ba5f7 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ The Tile object comes with several properties: - `accuracy`: the location accuracy of the Tile - `altitude`: the altitude of the Tile - `archetype`: the internal reference string that describes the Tile's "family" +- `battery_status`: the Tile's battery status (e.g., `NONE`, `LEVEL1`, `LEVEL2`) - `dead`: whether the Tile is inactive - `firmware_version`: the Tile's firmware version - `hardware_version`: the Tile's hardware version diff --git a/pytile/tile.py b/pytile/tile.py index 78cb180..1520ad4 100644 --- a/pytile/tile.py +++ b/pytile/tile.py @@ -9,7 +9,7 @@ from .const import LOGGER -class Tile: +class Tile: # pylint: disable=too-many-public-methods """Define a Tile.""" def __init__( @@ -69,6 +69,19 @@ def archetype(self) -> str: """ return cast(str, self._tile_data["result"]["archetype"]) + @property + def battery_status(self) -> str | None: + """Return the battery status. + + Observed values are "NONE", "LEVEL1" and "LEVEL2"; whether a Tile reports a + level at all depends on its firmware generation. The key is absent for some + node types, so this returns None rather than raising. + + Returns: + The battery status (if it exists). + """ + return cast("str | None", self._tile_data["result"].get("battery_status")) + @property def dead(self) -> bool: """Return whether the Tile is dead. @@ -237,6 +250,7 @@ def as_dict(self) -> dict[str, Any]: "accuracy": self.accuracy, "altitude": self.altitude, "archetype": self.archetype, + "battery_status": self.battery_status, "dead": self.dead, "firmware_version": self.firmware_version, "hardware_version": self.hardware_version, diff --git a/tests/test_tile.py b/tests/test_tile.py index d1c8cbb..3408229 100644 --- a/tests/test_tile.py +++ b/tests/test_tile.py @@ -125,6 +125,7 @@ async def test_get_tiles( assert tile.accuracy == 13.496111 assert tile.altitude == 0.4076319168123 assert tile.archetype == "WALLET" + assert tile.battery_status == "NONE" assert not tile.dead assert not tile.lost assert tile.firmware_version == "01.12.14.0" @@ -295,6 +296,7 @@ async def test_tile_as_dict( "accuracy": 13.496111, "altitude": 0.4076319168123, "archetype": "WALLET", + "battery_status": "NONE", "dead": False, "firmware_version": "01.12.14.0", "hardware_version": "02.09",