Advertisement
Guest User

Untitled

a guest
Dec 30th, 2020
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1.    def handle_message(self, hdr, args):
  2.         """Handle a message on this cluster."""
  3.         self.debug("ZCL request 0x%04x: %s", hdr.command_id, args)
  4.         i = 0
  5.         for arg in args:
  6.             self.info("index: %s value: %s", i, arg)
  7.             i += 1
  8.         self.warning("argument: %s", ",".join(map(str, args)))
  9.         if len(args) < 70:
  10.             return
  11.         self.info(
  12.             "Interesting attributes - 52: %s, 41: %s, 56: %s, 57: %s, 0: %s",
  13.             args[52],
  14.             args[41],
  15.             args[56],
  16.             args[57],
  17.             args[0],
  18.         )
  19.  
  20.         manual_unlocked_vals = [9,43]
  21.         manual_locked_vals = [14,44]
  22.         lock_state_identfiers = [50, 58, 62, 54, 51, 57, 53]
  23.         open_state_identfiers = [196, 200]
  24.         open_vals = [63, 29]
  25.         closed_vals = [60, 30]
  26.  
  27.         # Note sure if these are updates but seem to appear without the lock actually changing
  28.         fakes = [117]
  29.        
  30.         if args[0] in fakes:
  31.             return
  32.  
  33.         if args[52] == 180 and args[41] == 165:
  34.             self.warning("the lock is unlocked via the app")
  35.             self.endpoint.device.lock_bus.listener_event("lock_event", 2)
  36.         elif args[52] == 180 and args[41] == 162:
  37.             self.warning("the lock is locked via the app")
  38.             self.endpoint.device.lock_bus.listener_event("lock_event", 1)
  39.         elif args[52] in lock_state_identfiers and args[41] in manual_unlocked_vals:
  40.             self.warning("the lock is unlocked manually")
  41.             self.endpoint.device.lock_bus.listener_event("lock_event", 2)
  42.         elif args[52] in lock_state_identfiers and args[41] in manual_locked_vals:
  43.             self.warning("the lock is locked manually")
  44.             self.endpoint.device.lock_bus.listener_event("lock_event", 1)
  45.         elif args[52] == 189 and args[41] == 162:
  46.             self.warning("the lock is locked via auto lock")
  47.             self.endpoint.device.lock_bus.listener_event("lock_event", 1)
  48.         if args[52] in open_state_identfiers and args[41] in open_vals:
  49.             self.warning("the door is open")
  50.             self.endpoint.device.motion_bus.listener_event("motion_event", ON)
  51.         elif args[52] in open_state_identfiers and args[41] in closed_vals:
  52.             self.warning("the door is closed")
  53.             self.endpoint.device.motion_bus.listener_event("motion_event", OFF)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement