Skip to content

Commit 4210221

Browse files
committed
Initial information from device
1 parent c2865d6 commit 4210221

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

hnap/devices.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,30 @@
2424
from .soapclient import MethodCallError, SoapClient
2525

2626

27-
class Motion(SoapClient):
27+
class _Device(SoapClient):
28+
def __init__(self, *args, **kwargs):
29+
super().__init__(*args, **kwargs)
30+
self._device_info = {}
31+
32+
def login(self):
33+
super().login()
34+
info = dict(self.call('GetDeviceSettings'))
35+
for k in ['@xmlns', 'SOAPActions', 'GetDeviceSettingsResult']:
36+
info.pop(k, None)
37+
38+
try:
39+
info['ModuleTypes'] = info['ModuleTypes']['string']
40+
except KeyError:
41+
pass
42+
43+
self._device_info = info
44+
45+
@property
46+
def device_info(self):
47+
return self._device_info
48+
49+
50+
class Motion(_Device):
2851
def __init__(self, *args, delta=30, **kwargs):
2952
super().__init__(*args, **kwargs)
3053
self.delta = delta
@@ -93,19 +116,7 @@ def fromstring(cls, s):
93116
return getattr(cls, s)
94117

95118

96-
class Siren(SoapClient):
97-
def __init__(self, *args, **kwargs):
98-
super().__init__(*args, **kwargs)
99-
self._info = {}
100-
101-
@property
102-
def info(self):
103-
return self._info
104-
105-
def login(self):
106-
super().login()
107-
self._info.update({})
108-
119+
class Siren(_Device):
109120
def is_playing(self):
110121
res = self.call("GetSirenAlarmSettings", ModuleID=1, Controller=1)
111122
return res["IsSounding"] == "true"
@@ -132,7 +143,7 @@ def stop(self):
132143
raise MethodCallError(f"Unable to stop. Response: {ret}")
133144

134145

135-
class Water(SoapClient):
146+
class Water(_Device):
136147
def is_active(self):
137148
ret = self.call("GetWaterDetectorState", ModuleID=1)
138149
return ret.get("IsWater") == "true"

0 commit comments

Comments
 (0)