pyasyncialarm 2.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ """Python Library for interacting with IAlarm aka antifurto365 alarm."""
2
+
3
+ name = "pyasyncialarm"
pyasyncialarm/const.py ADDED
@@ -0,0 +1,168 @@
1
+ """Constants for iAlarm Home Assistant Integration."""
2
+
3
+ from datetime import datetime
4
+ from enum import Enum, IntEnum
5
+ from typing import Optional, TypedDict
6
+
7
+
8
+ class LogEntryType(TypedDict):
9
+ time: Optional[datetime]
10
+ area: int
11
+ event: str
12
+ name: str
13
+
14
+
15
+ class LogEntryTypeRaw(TypedDict):
16
+ Time: str
17
+ Area: int
18
+ Event: str
19
+ Name: str
20
+
21
+
22
+ EVENT_TYPE_MAP = {
23
+ "0000": "Unused",
24
+ "1100": "Personal ambulance",
25
+ "1101": "Emergency",
26
+ "1110": "Fire",
27
+ "1113": "Water",
28
+ "1120": "Emergency",
29
+ "1121": "Duress alarm",
30
+ "1122": "Personal ambulance",
31
+ "1131": "Perimeter",
32
+ "1132": "Burglary",
33
+ "1133": "24 hour",
34
+ "1134": "Delay",
35
+ "1137": "Dismantled",
36
+ "1151": "Gas",
37
+ "1154": "Water intrusion alarm",
38
+ "1301": "System AC fault",
39
+ "1302": "System battery failure",
40
+ "1306": "Programming changes",
41
+ "1321": "Siren fault",
42
+ "1350": "Communication failure",
43
+ "1351": "Telephone line fault",
44
+ "1370": "Circuit fault",
45
+ "1381": "Detector lost",
46
+ "1384": "Detector low battery",
47
+ "1401": "Disarm report",
48
+ "1406": "Alarm canceled",
49
+ "1455": "Automatic arming failed",
50
+ "1570": "Bypass Report",
51
+ "1601": "Manual communication test reports",
52
+ "1602": "Communications test reports",
53
+ "1901": "Gate magnetic switch open",
54
+ "3100": "Personal ambulance recovery",
55
+ "3110": "Fire recovery",
56
+ "3120": "Emergency recovery",
57
+ "3122": "Personal Ambulance Recovery",
58
+ "3131": "Perimeter recovery",
59
+ "3132": "Burglary recovery",
60
+ "3133": "24 hour recovery",
61
+ "3134": "Alarm delay recovery",
62
+ "3137": "Dismantled recovery",
63
+ "3301": "System AC recovery",
64
+ "3302": "System battery recovery",
65
+ "3321": "Siren recovery",
66
+ "3350": "Communication recovery",
67
+ "3351": "Telephone line to restore",
68
+ "3370": "Circuit recovery",
69
+ "3381": "Detector loss recovery",
70
+ "3384": "Detector low voltage recovery",
71
+ "3401": "Arming Report",
72
+ "3441": "Staying Report",
73
+ "3570": "Bypass recovery",
74
+ "3901": "Gate magnetic switch close",
75
+ "3994": "Video lost recovery",
76
+ "3995": "Video cover recovery",
77
+ "9984": "Video lost",
78
+ "9988": "Full hard disk",
79
+ "9991": "Hard disk format",
80
+ "9994": "Video lost",
81
+ "9995": "Video cover",
82
+ "9996": "Hard disk lost",
83
+ "9997": "Hard disk error",
84
+ "9999": "Motion detection",
85
+ }
86
+
87
+
88
+ class StatusType(IntEnum):
89
+ ZONE_NOT_USED = 0
90
+ ZONE_IN_USE = 1 << 0
91
+ ZONE_ALARM = 1 << 1
92
+ ZONE_BYPASS = 1 << 2
93
+ ZONE_FAULT = 1 << 3
94
+ ZONE_LOW_BATTERY = 1 << 4
95
+ ZONE_LOSS = 1 << 5
96
+
97
+
98
+ class ZoneStatusType(TypedDict):
99
+ zone_id: int
100
+ name: str
101
+ types: list[StatusType]
102
+
103
+
104
+ class ZoneTypeEnum(str, Enum):
105
+ UNUSED = "Unused"
106
+ DELAY = "Delay"
107
+ PERIMETER = "Perimeter"
108
+ INNER = "Inner"
109
+ EMERGENCY = "Emergency"
110
+ HOUR_24 = "24 Hour"
111
+ FIRE = "Fire"
112
+ KEY = "Key"
113
+ GAS = "Gas"
114
+ WATER = "Water"
115
+
116
+
117
+ class SirenSoundTypeEnum(str, Enum):
118
+ CONTINUED = "Continued"
119
+ PULSED = "Pulsed"
120
+ MUTE = "Mute"
121
+
122
+
123
+ TYPE_MAPPING = {
124
+ 0: ZoneTypeEnum.UNUSED,
125
+ 1: ZoneTypeEnum.DELAY,
126
+ 2: ZoneTypeEnum.PERIMETER,
127
+ 3: ZoneTypeEnum.INNER,
128
+ 4: ZoneTypeEnum.EMERGENCY,
129
+ 5: ZoneTypeEnum.HOUR_24,
130
+ 6: ZoneTypeEnum.FIRE,
131
+ 7: ZoneTypeEnum.KEY,
132
+ 8: ZoneTypeEnum.GAS,
133
+ 9: ZoneTypeEnum.WATER,
134
+ }
135
+
136
+ ZONE_TYPE_MAP = {
137
+ "NO": ZoneTypeEnum.UNUSED,
138
+ "DE": ZoneTypeEnum.DELAY,
139
+ "SI": ZoneTypeEnum.PERIMETER,
140
+ "IN": ZoneTypeEnum.INNER,
141
+ "FO": ZoneTypeEnum.EMERGENCY,
142
+ "HO24": ZoneTypeEnum.HOUR_24,
143
+ "FI": ZoneTypeEnum.FIRE,
144
+ "KE": ZoneTypeEnum.KEY,
145
+ "GAS": ZoneTypeEnum.GAS,
146
+ "WT": ZoneTypeEnum.WATER,
147
+ }
148
+
149
+ ALARM_TYPE_MAP = {
150
+ "CX": SirenSoundTypeEnum.CONTINUED,
151
+ "MC": SirenSoundTypeEnum.PULSED,
152
+ "NO": SirenSoundTypeEnum.MUTE,
153
+ }
154
+
155
+
156
+ class ZoneType(TypedDict):
157
+ zone_id: int
158
+ type: int
159
+ voice: int
160
+ name: str
161
+ bell: bool
162
+
163
+
164
+ class ZoneTypeRaw(TypedDict):
165
+ Type: int
166
+ Voice: int
167
+ Name: str
168
+ Bell: str
@@ -0,0 +1,14 @@
1
+ """Exceptions for iAlarm Home Assistant Integration."""
2
+
3
+ class IAlarmSocketNotOpenError(ConnectionError):
4
+ """Exception raised when socket is not open."""
5
+
6
+ def __init__(self):
7
+ super().__init__("Socket is not open")
8
+
9
+
10
+ class IAlarmConnectionError(ConnectionError):
11
+ """Exception raised when socket is not open."""
12
+
13
+ def __init__(self):
14
+ super().__init__("Connection to the alarm system failed")
@@ -0,0 +1,432 @@
1
+ import asyncio
2
+ from collections import OrderedDict
3
+ import logging
4
+ import re
5
+ import socket
6
+ from typing import Any, Optional
7
+
8
+ import dicttoxml2
9
+ import xmltodict
10
+
11
+ from pyasyncialarm.const import (
12
+ ALARM_TYPE_MAP,
13
+ EVENT_TYPE_MAP,
14
+ ZONE_TYPE_MAP,
15
+ LogEntryType,
16
+ LogEntryTypeRaw,
17
+ SirenSoundTypeEnum,
18
+ StatusType,
19
+ ZoneStatusType,
20
+ ZoneType,
21
+ ZoneTypeEnum,
22
+ ZoneTypeRaw,
23
+ )
24
+ from pyasyncialarm.exception import IAlarmConnectionError
25
+ from pyasyncialarm.util import decode_name, parse_bell, parse_time
26
+
27
+ log = logging.getLogger(__name__)
28
+ # dicttoxml is very verbose at INFO level
29
+ logging.getLogger("dicttoxml").setLevel(logging.CRITICAL)
30
+
31
+
32
+ class IAlarm:
33
+ """Interface the iAlarm security systems."""
34
+
35
+ ARMED_AWAY = 0
36
+ DISARMED = 1
37
+ ARMED_STAY = 2
38
+ CANCEL = 3
39
+ TRIGGERED = 4
40
+
41
+ def __init__(self, host, port=18034):
42
+ """:param host: host of the iAlarm security system (e.g. its IP address)
43
+ :param port: port of the iAlarm security system (should be '18034')
44
+ """
45
+ self.host = host
46
+ self.port = port
47
+ self.seq = 0
48
+ self.sock = None
49
+
50
+ def _is_socket_open(self) -> bool:
51
+ return self.sock is not None and self.sock.fileno() != -1
52
+
53
+ async def ensure_connection_is_open(self) -> None:
54
+ if not self._is_socket_open():
55
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
56
+ self.sock.setblocking(False)
57
+
58
+ self.seq = 0
59
+ loop = asyncio.get_running_loop()
60
+ try:
61
+ await loop.sock_connect(self.sock, (self.host, self.port))
62
+ except (TimeoutError, OSError, ConnectionRefusedError) as err:
63
+ self._close_connection()
64
+ raise IAlarmConnectionError from err
65
+ except Exception:
66
+ self._close_connection()
67
+ raise
68
+ else:
69
+ log.debug("Socket is already connected.")
70
+
71
+ def _close_connection(self) -> None:
72
+ if self.sock and self.sock.fileno() != -1:
73
+ self.sock.close()
74
+
75
+ async def _receive(self):
76
+ def raise_connection_error(msg: str):
77
+ self._close_connection()
78
+ raise ConnectionError(msg)
79
+
80
+ if not self._is_socket_open():
81
+ raise_connection_error("Socket is not open")
82
+
83
+ try:
84
+ self.sock.setblocking(False)
85
+ loop = asyncio.get_running_loop()
86
+ data = await loop.sock_recv(self.sock, 1024)
87
+
88
+ if not data:
89
+ raise_connection_error("Connection error, received no reply")
90
+
91
+ except Exception:
92
+ self._close_connection()
93
+ raise
94
+
95
+ payload = data[16:-4]
96
+ decoded = (
97
+ self._xor(payload).decode(errors="ignore").replace("<Err>ERR|00</Err>", "")
98
+ )
99
+
100
+ log.debug("Decoded data: %s", decoded)
101
+
102
+ if not decoded:
103
+ raise_connection_error("Connection error, received an unexpected reply")
104
+
105
+ return xmltodict.parse(
106
+ decoded,
107
+ xml_attribs=False,
108
+ dict_constructor=dict,
109
+ postprocessor=self._xmlread,
110
+ )
111
+
112
+ async def _send_request_list(
113
+ self,
114
+ xpath: str,
115
+ command: OrderedDict[str, Optional[Any]],
116
+ offset: int = 0,
117
+ partial_list: Optional[list[Any]] = None,
118
+ ) -> list[Any]:
119
+ if offset > 0:
120
+ command["Offset"] = "S32,0,0|%d" % offset
121
+ root_dict: dict[str, Any] = self._create_root_dict(xpath, command)
122
+ await self._send_dict(root_dict)
123
+ response: dict[str, Any] = await self._receive()
124
+
125
+ if partial_list is None:
126
+ partial_list = []
127
+ total: int = self._clean_response_dict(response, f"{xpath}/Total")
128
+ ln: int = self._clean_response_dict(response, f"{xpath}/Ln")
129
+ for i in range(ln):
130
+ partial_list.append(self._clean_response_dict(response, f"{xpath}/L{i}"))
131
+ offset += ln
132
+ if total > offset:
133
+ await self._send_request_list(xpath, command, offset, partial_list)
134
+
135
+ return partial_list
136
+
137
+ async def _send_request(
138
+ self, xpath: str, command: OrderedDict[str, Optional[Any]]
139
+ ) -> dict[str, Any]:
140
+ root_dict = self._create_root_dict(xpath, command)
141
+ await self._send_dict(root_dict)
142
+ response = await self._receive()
143
+ self._close_connection()
144
+ return self._clean_response_dict(response, xpath)
145
+
146
+ async def get_mac(self) -> str:
147
+ mac = ""
148
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
149
+ command["Mac"] = None
150
+ command["Name"] = None
151
+ command["Ip"] = None
152
+ command["Gate"] = None
153
+ command["Subnet"] = None
154
+ command["Dns1"] = None
155
+ command["Dns2"] = None
156
+ command["Err"] = None
157
+ network_info = await self._send_request("/Root/Host/GetNet", command)
158
+
159
+ if network_info is not None:
160
+ mac = network_info.get("Mac", "")
161
+
162
+ if mac:
163
+ return mac
164
+ error_message = (
165
+ "An error occurred trying to connect to the alarm system or received an"
166
+ " unexpected reply"
167
+ )
168
+ raise ConnectionError(error_message)
169
+
170
+ async def get_last_log_entries(self, max_entries: int = 25) -> list[LogEntryType]:
171
+ log_list = await self.get_log()
172
+ if not log_list:
173
+ return []
174
+ return log_list[:max_entries]
175
+
176
+ async def get_zone_status(self) -> list[ZoneStatusType]:
177
+ zones: list[ZoneType] = await self.get_zone()
178
+
179
+ zone_name_map = {zone["zone_id"]: zone["name"] for zone in zones}
180
+
181
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
182
+ command["Total"] = None
183
+ command["Offset"] = "S32,0,0|0"
184
+ command["Ln"] = None
185
+ command["Err"] = None
186
+ zone_status: list[int] = await self._send_request_list(
187
+ "/Root/Host/GetByWay", command
188
+ )
189
+
190
+ if zone_status is None:
191
+ error_message = "An error occurred trying to connect to the alarm system"
192
+ raise ConnectionError(error_message)
193
+
194
+ result = []
195
+ for i, status in enumerate(zone_status):
196
+ zone_id = i + 1
197
+
198
+ status_list = []
199
+
200
+ if status & StatusType.ZONE_IN_USE:
201
+ status_list.append(StatusType.ZONE_IN_USE)
202
+ if status & StatusType.ZONE_ALARM:
203
+ status_list.append(StatusType.ZONE_ALARM)
204
+ if status & StatusType.ZONE_BYPASS:
205
+ status_list.append(StatusType.ZONE_BYPASS)
206
+ if status & StatusType.ZONE_FAULT:
207
+ status_list.append(StatusType.ZONE_FAULT)
208
+ if status & StatusType.ZONE_LOW_BATTERY:
209
+ status_list.append(StatusType.ZONE_LOW_BATTERY)
210
+ if status & StatusType.ZONE_LOSS:
211
+ status_list.append(StatusType.ZONE_LOSS)
212
+
213
+ if not status_list:
214
+ status_list.append(StatusType.ZONE_NOT_USED)
215
+
216
+ zone_name = zone_name_map.get(zone_id, "Unknown")
217
+
218
+ zone_item: ZoneStatusType = {
219
+ "zone_id": zone_id,
220
+ "name": zone_name,
221
+ "types": status_list,
222
+ }
223
+ result.append(zone_item)
224
+
225
+ return result
226
+
227
+ async def get_status(self) -> int:
228
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
229
+ command["DevStatus"] = None
230
+ command["Err"] = None
231
+
232
+ alarm_status: dict[str, Any] = await self._send_request(
233
+ "/Root/Host/GetAlarmStatus", command
234
+ )
235
+
236
+ if alarm_status is None:
237
+ error_message = "An error occurred trying to connect to the alarm system"
238
+ raise ConnectionError(error_message)
239
+
240
+ status = int(alarm_status.get("DevStatus", -1))
241
+ if status == -1:
242
+ error_message = "Received an unexpected reply from the alarm"
243
+ raise ConnectionError(error_message)
244
+
245
+ if status in {self.ARMED_AWAY, self.ARMED_STAY}:
246
+ zone_status: list[ZoneStatusType] = await self.get_zone_status()
247
+ zone_alarm = any(
248
+ StatusType.ZONE_ALARM in zone["types"] for zone in zone_status
249
+ )
250
+
251
+ if zone_alarm:
252
+ return self.TRIGGERED
253
+
254
+ return status
255
+
256
+ async def get_log(self) -> list[LogEntryType]:
257
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
258
+ command["Total"] = None
259
+ command["Offset"] = "S32,0,0|0"
260
+ command["Ln"] = None
261
+ command["Err"] = None
262
+
263
+ event_log_raw: list[LogEntryTypeRaw] = await self._send_request_list(
264
+ "/Root/Host/GetLog", command
265
+ )
266
+
267
+ logs = [
268
+ LogEntryType(
269
+ time=parse_time(event["Time"]),
270
+ area=event["Area"],
271
+ event=EVENT_TYPE_MAP.get(event["Event"], event["Event"]),
272
+ name=decode_name(event["Name"]),
273
+ )
274
+ for event in event_log_raw
275
+ ]
276
+
277
+ return logs
278
+
279
+ def __extract_zones(self, zone_data_raw: list[ZoneTypeRaw]) -> list[ZoneType]:
280
+ return [
281
+ ZoneType(
282
+ zone_id=i,
283
+ type=zone["Type"],
284
+ voice=zone["Voice"],
285
+ name=decode_name(zone["Name"]),
286
+ bell=parse_bell(zone["Bell"]),
287
+ )
288
+ for i, zone in enumerate(zone_data_raw, start=1)
289
+ ]
290
+
291
+ async def get_zone(self) -> list[ZoneType]:
292
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
293
+ command["Total"] = None
294
+ command["Offset"] = "S32,0,0|0"
295
+ command["Ln"] = None
296
+ command["Err"] = None
297
+
298
+ raw_zone_data: list[ZoneTypeRaw] = await self._send_request_list(
299
+ "/Root/Host/GetZone", command
300
+ )
301
+ zone: list[ZoneType] = self.__extract_zones(raw_zone_data)
302
+
303
+ return zone
304
+
305
+ async def get_zone_type(self) -> list[ZoneTypeEnum]:
306
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
307
+ command["Total"] = None
308
+ command["Offset"] = "S32,0,0|0"
309
+ command["Ln"] = None
310
+ command["Err"] = None
311
+
312
+ zone_type_codes = await self._send_request_list(
313
+ "/Root/Host/GetZoneType", command
314
+ )
315
+ zone_types = [
316
+ ZONE_TYPE_MAP.get(code, ZoneTypeEnum.UNUSED) for code in zone_type_codes
317
+ ]
318
+
319
+ return zone_types
320
+
321
+ async def get_alarm_type(self) -> list[SirenSoundTypeEnum]:
322
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
323
+ command["Total"] = None
324
+ command["Offset"] = "S32,0,0|0"
325
+ command["Ln"] = None
326
+ command["Err"] = None
327
+
328
+ alarm_type_codes = await self._send_request_list(
329
+ "/Root/Host/GetVoiceType", command
330
+ )
331
+ zone_types = [
332
+ ALARM_TYPE_MAP.get(code, SirenSoundTypeEnum.CONTINUED)
333
+ for code in alarm_type_codes
334
+ ]
335
+
336
+ return zone_types
337
+
338
+ async def arm_away(self) -> None:
339
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
340
+ command["DevStatus"] = "TYP,ARM|0"
341
+ command["Err"] = None
342
+ await self._send_request("/Root/Host/SetAlarmStatus", command)
343
+
344
+ async def arm_stay(self) -> None:
345
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
346
+ command["DevStatus"] = "TYP,STAY|2"
347
+ command["Err"] = None
348
+ await self._send_request("/Root/Host/SetAlarmStatus", command)
349
+
350
+ async def disarm(self) -> None:
351
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
352
+ command["DevStatus"] = "TYP,DISARM|1"
353
+ command["Err"] = None
354
+ await self._send_request("/Root/Host/SetAlarmStatus", command)
355
+
356
+ async def cancel_alarm(self) -> None:
357
+ command: OrderedDict[str, Optional[Any]] = OrderedDict()
358
+ command["DevStatus"] = "TYP,CLEAR|3"
359
+ command["Err"] = None
360
+ await self._send_request("/Root/Host/SetAlarmStatus", command)
361
+
362
+ async def _send_dict(self, root_dict) -> None:
363
+ xml = dicttoxml2.dicttoxml(root_dict, attr_type=False, root=False)
364
+
365
+ await self.ensure_connection_is_open()
366
+
367
+ self.seq += 1
368
+ msg = b"@ieM%04d%04d0000%s%04d" % (len(xml), self.seq, self._xor(xml), self.seq)
369
+
370
+ loop = asyncio.get_running_loop()
371
+ await loop.sock_sendall(self.sock, msg)
372
+
373
+ @staticmethod
374
+ def _xmlread(_path, key, value):
375
+ if value is None or not isinstance(value, str):
376
+ return key, value
377
+
378
+ err_re = re.compile(r"ERR\|(\d{2})")
379
+ mac_re = re.compile(r"MAC,(\d+)\|(([0-9A-F]{2}[:-]){5}([0-9A-F]{2}))")
380
+ s32_re = re.compile(r"S32,(\d+),(\d+)\|(\d*)")
381
+ str_re = re.compile(r"STR,(\d+)\|(.*)")
382
+ typ_re = re.compile(r"TYP,(\w+)\|(\d+)")
383
+ if err_re.match(value):
384
+ value = int(err_re.search(value).groups()[0])
385
+ elif mac_re.match(value):
386
+ value = str(mac_re.search(value).groups()[1])
387
+ elif s32_re.match(value):
388
+ value = int(s32_re.search(value).groups()[2])
389
+ elif str_re.match(value):
390
+ value = str(str_re.search(value).groups()[1])
391
+ elif typ_re.match(value):
392
+ value = int(typ_re.search(value).groups()[1])
393
+ # Else: we are not interested in this value, just keep it as is
394
+
395
+ return key, value
396
+
397
+ @staticmethod
398
+ def _create_root_dict(path, my_dict=None):
399
+ if my_dict is None:
400
+ my_dict = {}
401
+ root = {}
402
+ elem = root
403
+ plist = path.strip("/").split("/")
404
+ k = len(plist) - 1
405
+ for i, j in enumerate(plist):
406
+ elem[j] = {}
407
+ if i == k:
408
+ elem[j] = my_dict
409
+ elem = elem.get(j)
410
+ return root
411
+
412
+ @staticmethod
413
+ def _clean_response_dict(response, path):
414
+ for i in path.strip("/").split("/"):
415
+ try:
416
+ i = int(i)
417
+ response = response[i]
418
+ except ValueError:
419
+ response = response.get(i)
420
+ return response
421
+
422
+ @staticmethod
423
+ def _xor(xml):
424
+ sz = bytearray.fromhex(
425
+ "0c384e4e62382d620e384e4e44382d300f382b382b0c5a6234384e304e4c372b10535a0c20432d171142444e58422c421157322a204036172056446262382b5f0c384e4e62382d620e385858082e232c0f382b382b0c5a62343830304e2e362b10545a0c3e432e1711384e625824371c1157324220402c17204c444e624c2e12"
426
+ )
427
+ buf = bytearray(xml)
428
+ for i in range(len(xml)):
429
+ ki = i & 0x7F
430
+ buf[i] = buf[i] ^ sz[ki]
431
+
432
+ return buf
pyasyncialarm/util.py ADDED
@@ -0,0 +1,31 @@
1
+ """Utils for iAlarm Home Assistant Integration."""
2
+
3
+ from datetime import datetime
4
+ from typing import Optional
5
+
6
+
7
+ def parse_time(time_str: str) -> Optional[datetime]:
8
+ """Convert a time string to a datetime object."""
9
+ if "DTA,19" in time_str:
10
+ try:
11
+ return datetime.strptime(time_str.split("|")[1], "%Y.%m.%d.%H.%M.%S")
12
+ except (ValueError, IndexError):
13
+ return None
14
+ return None
15
+
16
+
17
+ def decode_name(name_str: str) -> str:
18
+ """Decode a hexadecimal name."""
19
+ if "GBA" in name_str:
20
+ try:
21
+ return bytes.fromhex(name_str.split("|")[1]).decode(
22
+ "utf-8", errors="ignore"
23
+ )
24
+ except (ValueError, IndexError):
25
+ return name_str
26
+ return name_str
27
+
28
+
29
+ def parse_bell(bell_value: str) -> bool:
30
+ """Convert the value 'Bell' to a boolean, checking 'BOL|T' for True."""
31
+ return bell_value == "BOL|T"
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyasyncialarm
3
+ Version: 2.3.0
4
+ Summary: A simple library to interface with iAlarm systems, built for use with Home-Assistant
5
+ Author-email: Ludovico de Nittis <aasonykk+pyasyncialarm@gmail.com>
6
+ License: MIT OR Apache-2.0
7
+ Project-URL: Homepage, https://github.com/bigmoby/pyasyncialarm
8
+ Project-URL: Source Code, https://github.com/bigmoby/pyasyncialarm
9
+ Project-URL: Bug Reports, https://github.com/bigmoby/pyasyncialarm/issues
10
+ Keywords: ialarm,antifurtocasa365,alarm
11
+ Platform: any
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Requires-Python: >=3.11.0
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: dicttoxml2
22
+ Requires-Dist: xmltodict
23
+
24
+ # pyasyncialarm
25
+ Python library to interface with [iAlarm systems](https://www.antifurtocasa365.it/).
26
+
27
+ It has also been confirmed to work with the alarm systems brands Meian and Emooluxr.
28
+
29
+ From the version 1.0 this library switched from webscraping the local configuration webpage to using the API that Android and iOS app use.
30
+ Thanks to https://github.com/wildstray/meian-client for writing down the API specs.
31
+
32
+
33
+ ## Development
34
+
35
+ Please run before creating a PR:
36
+
37
+ `pre-commit run --all-files`
38
+
39
+ and
40
+
41
+ `pytest -vv tests/test_pyasyncialarm.py`
@@ -0,0 +1,10 @@
1
+ pyasyncialarm/__init__.py,sha256=W70V-3XEFpdL94j0hDeInAh3y-MZB9etHL87gYtBOFY,97
2
+ pyasyncialarm/const.py,sha256=LVnjcPq-csx4kyJASWJi0oy9GHJQdWpaRJurwYSNRok,3974
3
+ pyasyncialarm/exception.py,sha256=vLnrzn2zLLdlr82GbcN-83F16R-ByDKlosK39EhJz0o,421
4
+ pyasyncialarm/pyasyncialarm.py,sha256=tghEp9aVQhT2cZ18fSbtzcWqOpND1pvFbrmQehcFSeg,14424
5
+ pyasyncialarm/util.py,sha256=9HE75XFZpfdkGxRdIAlm9W9tcmgU1uOe6KaiGEwHEyg,902
6
+ pyasyncialarm-2.3.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ pyasyncialarm-2.3.0.dist-info/METADATA,sha256=FRcYPDQ06fDtdAsmxvHqSy4ERoncmfBcaCg_8zkdW-A,1491
8
+ pyasyncialarm-2.3.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
9
+ pyasyncialarm-2.3.0.dist-info/top_level.txt,sha256=x_wGPr0ntLkb95oDpZ459gq6UXnVI2Ov4f2Uf3IFNdM,14
10
+ pyasyncialarm-2.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.40.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ pyasyncialarm