Skip to content

Commit 5d8d004

Browse files
authored
Add support for cover sensor (#55)
1 parent c9eea7f commit 5d8d004

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

smarttub/__main__.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async def info_command(spas, args):
1414
for spa in spas:
1515
print(f"= Spa '{spa.name}' =\n")
1616
if args.all or args.status or args.location or args.locks:
17-
status = await spa.get_status()
17+
status = await spa.get_status_full()
1818

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

3333
if args.all or args.pumps:
3434
print("== Pumps ==")
35-
for pump in await spa.get_pumps():
35+
for pump in status.pumps:
3636
print(pump)
3737
print()
3838

3939
if args.all or args.lights:
4040
print("== Lights ==")
41-
for light in await spa.get_lights():
41+
for light in status.lights:
4242
print(light)
4343
print()
4444

@@ -70,6 +70,12 @@ async def info_command(spas, args):
7070
pprint(await energy_usage_day)
7171
print()
7272

73+
if args.all or args.sensors:
74+
print("== Sensors ==")
75+
for sensor in status.sensors:
76+
print(sensor)
77+
print()
78+
7379
if args.all or args.debug:
7480
debug_status = await spa.get_debug_status()
7581
print("== Debug status ==")
@@ -152,6 +158,7 @@ async def main(argv):
152158
info_parser.add_argument("--reminders", action="store_true")
153159
info_parser.add_argument("--locks", action="store_true")
154160
info_parser.add_argument("--debug", action="store_true")
161+
info_parser.add_argument("--sensors", action="store_true")
155162
info_parser.add_argument("--energy", action="store_true")
156163

157164
set_parser = subparsers.add_parser("set", help="Change settings on the spa")

smarttub/api.py

+20
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ def __init__(self, spa: Spa, state: dict):
373373
self.pumps = [
374374
SpaPump(spa, **pump_props) for pump_props in self.properties["pumps"]
375375
]
376+
self.sensors = [
377+
SpaSensor(spa, **sensor_props) for sensor_props in self.properties.get("sensors", [])
378+
]
376379

377380

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

560563

564+
class SpaSensor:
565+
def __init__(self, spa: Spa, **properties):
566+
self.spa = spa
567+
self.address = properties["address"]
568+
self.name = properties["name"]
569+
self.type = properties["type"]
570+
self.subType = properties["subType"]
571+
572+
self.magnet = properties["magnet"]
573+
self.pressure = properties["pressure"]
574+
self.motion = properties["motion"]
575+
self.fill_drain = properties["fill_drain"]
576+
577+
def __str__(self):
578+
return f"<SpaSensor {self.name} ({self.type})"
579+
580+
561581
class LoginFailed(RuntimeError):
562582
pass
563583

tests/test_spa.py

+26
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ async def test_get_status_full(mock_api, spa):
209209
"mode": "AWAY",
210210
"status": "INACTIVE",
211211
},
212+
"sensors": [],
212213
"setTemperature": 38.3,
213214
"state": "NORMAL",
214215
"time": "14:05:00",
@@ -336,6 +337,31 @@ async def test_null_blowout(mock_api, spa):
336337
"mode": "AWAY",
337338
"status": "INACTIVE",
338339
},
340+
"sensors": [
341+
{
342+
"id": 13914100,
343+
"spaId": "1",
344+
"address": "C7:54:EE:BB:AA:AA",
345+
"type": "ibs0x",
346+
"name": "{cover-sensor-1}",
347+
"subType": "magnet",
348+
"voltage": 3.07,
349+
"rssi": -56,
350+
"age": 0,
351+
"fill_drain": None,
352+
"configState": '{"drainBit":0,"mode":null,"sensorSetTime":null}',
353+
"motion": None,
354+
"magnet": True,
355+
"digital": None,
356+
"button": False,
357+
"triggeredCount": 18,
358+
"missedCount": 0,
359+
"snoozeUntil": "2025-02-17T19:19:38.879670Z",
360+
"pressure": None,
361+
"updatedAt": None,
362+
"createdAt": "2025-02-17T19:19:38.879695Z",
363+
}
364+
],
339365
"setTemperature": 38.3,
340366
"state": "NORMAL",
341367
"time": "14:05:00",

0 commit comments

Comments
 (0)