|
24 | 24 | from .soapclient import MethodCallError, SoapClient |
25 | 25 |
|
26 | 26 |
|
| 27 | +def DeviceFactory(hostname, password, username="Admin", port=80, **kwargs): |
| 28 | + device = SoapClient(hostname, password, username, port) |
| 29 | + device.authenticate() |
| 30 | + info = device.device_info() |
| 31 | + |
| 32 | + module_types = info["ModuleTypes"] |
| 33 | + if not isinstance(module_types, list): |
| 34 | + module_types = [module_types] |
| 35 | + |
| 36 | + if "Audio Renderer" in module_types: |
| 37 | + cls = Siren |
| 38 | + # 'Optical Recognition', 'Environmental Sensor', 'Camera'] |
| 39 | + elif "Camera" in module_types: |
| 40 | + cls = Camera |
| 41 | + elif "Motion Sensor" in module_types: |
| 42 | + cls = Motion |
| 43 | + else: |
| 44 | + raise TypeError(module_types) |
| 45 | + |
| 46 | + return cls(hostname, password, username=username, port=port, **kwargs) |
| 47 | + |
| 48 | + |
27 | 49 | class _Device(SoapClient): |
28 | 50 | def __init__(self, *args, **kwargs): |
29 | 51 | super().__init__(*args, **kwargs) |
30 | | - self._device_info = {} |
| 52 | + self._info = None |
31 | 53 |
|
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) |
| 54 | + def authenticate(self): |
| 55 | + super().authenticate() |
| 56 | + self._info = self.device_info() |
37 | 57 |
|
38 | | - try: |
39 | | - info['ModuleTypes'] = info['ModuleTypes']['string'] |
40 | | - except KeyError: |
41 | | - pass |
| 58 | + @property |
| 59 | + def info(self): |
| 60 | + return self._info |
42 | 61 |
|
43 | | - self._device_info = info |
44 | 62 |
|
45 | | - @property |
46 | | - def device_info(self): |
47 | | - return self._device_info |
| 63 | +class Camera(_Device): |
| 64 | + pass |
48 | 65 |
|
49 | 66 |
|
50 | 67 | class Motion(_Device): |
|
0 commit comments