Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion pytile/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .const import LOGGER


class Tile:
class Tile: # pylint: disable=too-many-public-methods
"""Define a Tile."""

def __init__(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
Loading