Skip to content

Commit

Permalink
Add support for cover sensor (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdz authored Feb 23, 2025
1 parent c9eea7f commit 5d8d004
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
13 changes: 10 additions & 3 deletions smarttub/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def info_command(spas, args):
for spa in spas:
print(f"= Spa '{spa.name}' =\n")
if args.all or args.status or args.location or args.locks:
status = await spa.get_status()
status = await spa.get_status_full()

if args.all or args.status:
print("== Status ==")
Expand All @@ -32,13 +32,13 @@ async def info_command(spas, args):

if args.all or args.pumps:
print("== Pumps ==")
for pump in await spa.get_pumps():
for pump in status.pumps:
print(pump)
print()

if args.all or args.lights:
print("== Lights ==")
for light in await spa.get_lights():
for light in status.lights:
print(light)
print()

Expand Down Expand Up @@ -70,6 +70,12 @@ async def info_command(spas, args):
pprint(await energy_usage_day)
print()

if args.all or args.sensors:
print("== Sensors ==")
for sensor in status.sensors:
print(sensor)
print()

if args.all or args.debug:
debug_status = await spa.get_debug_status()
print("== Debug status ==")
Expand Down Expand Up @@ -152,6 +158,7 @@ async def main(argv):
info_parser.add_argument("--reminders", action="store_true")
info_parser.add_argument("--locks", action="store_true")
info_parser.add_argument("--debug", action="store_true")
info_parser.add_argument("--sensors", action="store_true")
info_parser.add_argument("--energy", action="store_true")

set_parser = subparsers.add_parser("set", help="Change settings on the spa")
Expand Down
20 changes: 20 additions & 0 deletions smarttub/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ def __init__(self, spa: Spa, state: dict):
self.pumps = [
SpaPump(spa, **pump_props) for pump_props in self.properties["pumps"]
]
self.sensors = [
SpaSensor(spa, **sensor_props) for sensor_props in self.properties.get("sensors", [])
]


class SpaWaterState(SpaState):
Expand Down Expand Up @@ -558,6 +561,23 @@ def __str__(self):
return f"<SpaLock {self.kind}: {self.state}>"


class SpaSensor:
def __init__(self, spa: Spa, **properties):
self.spa = spa
self.address = properties["address"]
self.name = properties["name"]
self.type = properties["type"]
self.subType = properties["subType"]

self.magnet = properties["magnet"]
self.pressure = properties["pressure"]
self.motion = properties["motion"]
self.fill_drain = properties["fill_drain"]

def __str__(self):
return f"<SpaSensor {self.name} ({self.type})"


class LoginFailed(RuntimeError):
pass

Expand Down
26 changes: 26 additions & 0 deletions tests/test_spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ async def test_get_status_full(mock_api, spa):
"mode": "AWAY",
"status": "INACTIVE",
},
"sensors": [],
"setTemperature": 38.3,
"state": "NORMAL",
"time": "14:05:00",
Expand Down Expand Up @@ -336,6 +337,31 @@ async def test_null_blowout(mock_api, spa):
"mode": "AWAY",
"status": "INACTIVE",
},
"sensors": [
{
"id": 13914100,
"spaId": "1",
"address": "C7:54:EE:BB:AA:AA",
"type": "ibs0x",
"name": "{cover-sensor-1}",
"subType": "magnet",
"voltage": 3.07,
"rssi": -56,
"age": 0,
"fill_drain": None,
"configState": '{"drainBit":0,"mode":null,"sensorSetTime":null}',
"motion": None,
"magnet": True,
"digital": None,
"button": False,
"triggeredCount": 18,
"missedCount": 0,
"snoozeUntil": "2025-02-17T19:19:38.879670Z",
"pressure": None,
"updatedAt": None,
"createdAt": "2025-02-17T19:19:38.879695Z",
}
],
"setTemperature": 38.3,
"state": "NORMAL",
"time": "14:05:00",
Expand Down

0 comments on commit 5d8d004

Please sign in to comment.