|
11 | 11 | from .decorators import require_lock, require_session |
12 | 12 | from .exceptions import ( |
13 | 13 | CodeError, |
| 14 | + CommandError, |
14 | 15 | CredentialError, |
15 | | - InvalidInput, |
16 | | - InvalidSector, |
17 | 16 | InvalidToken, |
18 | 17 | LockError, |
19 | 18 | ParseError, |
@@ -263,20 +262,14 @@ def arm(self, sectors=None): |
263 | 262 | # Send the payload to arm sectors |
264 | 263 | response = self._session.post(self._router.send_command, data=payload) |
265 | 264 | response.raise_for_status() |
266 | | - |
267 | | - errors = [] |
268 | | - # A not existing sector returns 200 with a fail state |
269 | 265 | body = response.json() |
270 | | - _LOGGER.debug(f"Client | Arming response: {body}") |
271 | | - if not body[0]["Successful"]: |
272 | | - errors.append(payload["ElementsIndexes"]) |
273 | 266 |
|
274 | | - # Raise an exception if errors are detected |
275 | | - if errors: |
276 | | - invalid_sectors = ",".join(str(x) for x in errors) |
277 | | - raise InvalidSector("Selected sectors don't exist: {}".format(invalid_sectors)) |
| 267 | + # Errors returns 200 with "Successful == False" JSON key |
| 268 | + if not body[0]["Successful"]: |
| 269 | + _LOGGER.error(f"Client | Arming response: {body}") |
| 270 | + raise CommandError |
278 | 271 |
|
279 | | - _LOGGER.debug("Client | Arming successful") |
| 272 | + _LOGGER.debug(f"Client | Arming successful with response: {body}") |
280 | 273 | return True |
281 | 274 |
|
282 | 275 | @require_session |
@@ -323,20 +316,14 @@ def disarm(self, sectors=None): |
323 | 316 | # Send the payload to disarm sectors |
324 | 317 | response = self._session.post(self._router.send_command, data=payload) |
325 | 318 | response.raise_for_status() |
326 | | - |
327 | | - errors = [] |
328 | | - # A not existing sector returns 200 with a fail state |
329 | 319 | body = response.json() |
330 | | - _LOGGER.debug(f"Client | Disarming response: {body}") |
331 | | - if not body[0]["Successful"]: |
332 | | - errors.append(payload["ElementsIndexes"]) |
333 | 320 |
|
334 | | - # Raise an exception if errors are detected |
335 | | - if errors: |
336 | | - invalid_sectors = ",".join(str(x) for x in errors) |
337 | | - raise InvalidSector("Selected sectors don't exist: {}".format(invalid_sectors)) |
| 321 | + # Errors returns 200 with "Successful == False" JSON key |
| 322 | + if not body[0]["Successful"]: |
| 323 | + _LOGGER.error(f"Client | Disarming response: {body}") |
| 324 | + raise CommandError |
338 | 325 |
|
339 | | - _LOGGER.debug("Client | Disarming successful") |
| 326 | + _LOGGER.debug(f"Client | Disarming successful with response: {body}") |
340 | 327 | return True |
341 | 328 |
|
342 | 329 | @require_session |
@@ -392,7 +379,7 @@ def exclude(self, inputs): |
392 | 379 | # Raise an exception if errors are detected |
393 | 380 | if errors: |
394 | 381 | invalid_inputs = ",".join(str(x) for x in errors) |
395 | | - raise InvalidInput("Selected inputs don't exist: {}".format(invalid_inputs)) |
| 382 | + raise CommandError("Selected inputs don't exist: {}".format(invalid_inputs)) |
396 | 383 |
|
397 | 384 | _LOGGER.debug("Client | Excluding successful") |
398 | 385 | return True |
@@ -450,7 +437,7 @@ def include(self, inputs): |
450 | 437 | # Raise an exception if errors are detected |
451 | 438 | if errors: |
452 | 439 | invalid_inputs = ",".join(str(x) for x in errors) |
453 | | - raise InvalidInput("Selected inputs don't exist: {}".format(invalid_inputs)) |
| 440 | + raise CommandError("Selected inputs don't exist: {}".format(invalid_inputs)) |
454 | 441 |
|
455 | 442 | _LOGGER.debug("Client | Including successful") |
456 | 443 | return True |
@@ -488,24 +475,17 @@ def turn_on(self, outputs): |
488 | 475 | "sessionId": self._session_id, |
489 | 476 | } |
490 | 477 |
|
491 | | - errors = [] |
492 | | - |
493 | 478 | # Send turn on request |
494 | 479 | response = self._session.post(self._router.send_command, data=payload) |
495 | 480 | response.raise_for_status() |
496 | | - |
497 | | - # A not existing output returns 200 with a fail state |
498 | 481 | body = response.json() |
499 | | - _LOGGER.debug(f"Client | Turning on response: {body}") |
500 | | - if not body[0]["Successful"]: |
501 | | - errors.append(payload["ElementsIndexes"]) |
502 | 482 |
|
503 | | - # Raise an exception if errors are detected |
504 | | - if errors: |
505 | | - invalid_outputs = ",".join(str(x) for x in errors) |
506 | | - raise InvalidInput("Selected outputs don't exist: {}".format(invalid_outputs)) |
| 483 | + # Errors returns 200 with "Successful == False" JSON key |
| 484 | + if not body[0]["Successful"]: |
| 485 | + _LOGGER.error(f"Client | Turning on response: {body}") |
| 486 | + raise CommandError |
507 | 487 |
|
508 | | - _LOGGER.debug("Client | Turning on output successful") |
| 488 | + _LOGGER.debug(f"Client | Turning on successful with response: {body}") |
509 | 489 | return True |
510 | 490 |
|
511 | 491 | @require_session |
@@ -544,20 +524,14 @@ def turn_off(self, outputs): |
544 | 524 | # Send turn off request |
545 | 525 | response = self._session.post(self._router.send_command, data=payload) |
546 | 526 | response.raise_for_status() |
547 | | - |
548 | | - errors = [] |
549 | | - # A not existing output returns 200 with a fail state |
550 | 527 | body = response.json() |
551 | | - _LOGGER.debug(f"Client | Turning off response: {body}") |
552 | | - if not body[0]["Successful"]: |
553 | | - errors.append(payload["ElementsIndexes"]) |
554 | 528 |
|
555 | | - # Raise an exception if errors are detected |
556 | | - if errors: |
557 | | - invalid_outputs = ",".join(str(x) for x in errors) |
558 | | - raise InvalidInput("Selected outputs don't exist: {}".format(invalid_outputs)) |
| 529 | + # Errors returns 200 with "Successful == False" JSON key |
| 530 | + if not body[0]["Successful"]: |
| 531 | + _LOGGER.error(f"Client | Turning on response: {body}") |
| 532 | + raise CommandError |
559 | 533 |
|
560 | | - _LOGGER.debug("Client | Turning off output successful") |
| 534 | + _LOGGER.debug(f"Client | Turning on successful with response: {body}") |
561 | 535 | return True |
562 | 536 |
|
563 | 537 | @lru_cache(maxsize=1) |
|
0 commit comments