- Files:
-
- 9 added
- 8 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/D_VistaAlarmPanel1.json
r20 r30 103 103 }, 104 104 { 105 "Label": { 106 "lang_tag": "settings", 107 "text": "Settings" 108 }, 109 "Position": "1", 110 "TabType": "javascript", 111 "ScriptName": "shared.js", 112 "Function": "simple_device" 113 }, 114 { 105 115 "Label": { 106 116 "lang_tag": "advanced", 107 117 "text": "Advanced" 108 118 }, 109 "Position": " 1",119 "Position": "2", 110 120 "TabType": "javascript", 111 121 "ScriptName": "shared.js", -
/trunk/D_VistaAlarmPartition1.json
r20 r30 568 568 } 569 569 } 570 }, 571 "event_3": { 572 "label": "Alarm Active", 573 "serviceId": "urn:micasaverde-com:serviceId:AlarmPartition2", 574 "argumentList" : { 575 "argument_1" : { 576 "dataType": "boolean", 577 "defaultValue": "Active", 578 "allowedValueList" : { 579 "Active" : "Active", 580 "NotActive" : "None" 581 }, 582 "name": "Alarm", 583 "comparisson": "=", 584 "prefix": "Is Active?", 585 "suffix": "" 586 } 587 } 570 588 } 571 589 }, … … 573 591 "group_1": { 574 592 "cmd_1": { 575 "label": " Set Partition ... (PIN)",593 "label": "Arm/Disarm partition", 576 594 "serviceId": "urn:micasaverde-com:serviceId:AlarmPartition2", 577 595 "action": "RequestArmMode", … … 600 618 }, 601 619 "prefix" : "PIN", 602 "suffix" : "0-9999 (insecure)", 620 "suffix" : "(insecure)", 621 "name": "PINCode" 622 } 623 } 624 } 625 }, 626 "group_2": { 627 "cmd_1": { 628 "label": "Press lettered key", 629 "serviceId": "urn:micasaverde-com:serviceId:VistaAlarmPanel1", 630 "action": "RequestLetteredKeyPress", 631 "argumentList": { 632 "argument_1": { 633 "dataType": "string", 634 "defaultValue": "D", 635 "allowedValueList": { 636 "A" : "A", 637 "B" : "B", 638 "C" : "C", 639 "D" : "D" 640 }, 641 "name": "Key", 642 "prefix": "Key", 643 "suffix": "(A, B, C or D)" 644 }, 645 "argument_2": { 646 "dataType": "string", 647 "defaultValue": "1234", 648 "allowedValueRange": { 649 "minimum": "0", 650 "maximum": "9999" 651 }, 652 "prefix" : "PIN", 653 "suffix" : "(insecure)", 654 "name": "PINCode" 655 } 656 } 657 } 658 }, 659 "group_3": { 660 "cmd_1": { 661 "label": "Change chime mode", 662 "serviceId": "urn:micasaverde-com:serviceId:VistaAlarmPanel1", 663 "action": "SetChimeMode", 664 "argumentList": { 665 "argument_1": { 666 "dataType": "boolean", 667 "defaultValue": "0", 668 "allowedValueList": { 669 "1" : "1", 670 "0" : "0" 671 }, 672 "name": "Mode", 673 "prefix": "Mode", 674 "suffix": "(1 or 0)" 675 }, 676 "argument_2": { 677 "dataType": "string", 678 "defaultValue": "1234", 679 "allowedValueRange": { 680 "minimum": "0", 681 "maximum": "9999" 682 }, 683 "prefix" : "PIN", 684 "suffix" : "(insecure)", 603 685 "name": "PINCode" 604 686 } -
/trunk/S_VistaAlarmPanel1.xml
r20 r30 73 73 </action> 74 74 <action> 75 <name>SetChimeMode</name> 76 <argumentList> 77 <argument> 78 <name>Mode</name> 79 <direction>in</direction> 80 <relatedStateVariable>ChimeMode</relatedStateVariable> 81 </argument> 82 <argument> 83 <name>PINCode</name> 84 <direction>in</direction> 85 <relatedStateVariable>string</relatedStateVariable> 86 </argument> 87 </argumentList> 88 </action> 89 <action> 75 90 <name>StorePinCode</name> 76 91 <argumentList> -
/trunk/I_VistaAlarmPanel1.xml
r20 r30 69 69 <action> 70 70 <serviceId>urn:micasaverde-com:serviceId:VistaAlarmPanel1</serviceId> 71 <name>SetChimeMode</name> 72 <run> 73 vistaPlugin.setChimeMode (lul_device, lul_settings.Mode, lul_settings.PINCode) 74 </run> 75 </action> 76 77 <action> 78 <serviceId>urn:micasaverde-com:serviceId:VistaAlarmPanel1</serviceId> 71 79 <name>StorePinCode</name> 72 80 <run> -
/trunk/L_VistaAlarmPanel1.lua
r20 r30 5 5 6 6 -- Constants 7 local VERSION = "2. 2"7 local VERSION = "2.30" 8 8 local DEBUG_MODE_DEFAULT = "1" 9 9 … … 11 11 12 12 local TTL = 60 -- If the panel doesn't report a zone as faulted in this number of seconds, the zone is considered unfaulted. 13 13 -- The timer is reset every time a fault report for this zone is received. 14 14 local TIMER_INTERVAL = 5 -- The delay used in the 'ttlCountdownTimer' function (luup.call_delay). 15 15 local SLEEP_MS = 250 … … 17 17 local SID = { 18 18 PANEL = "urn:micasaverde-com:serviceId:VistaAlarmPanel1", 19 PARTITION = "urn:micasaverde-com:serviceId:AlarmPartition2" 19 PARTITION = "urn:micasaverde-com:serviceId:AlarmPartition2", 20 SECURITY_SENSOR = "urn:micasaverde-com:serviceId:SecuritySensor1" 20 21 } 21 22 … … 45 46 46 47 local g_addrPart = {} -- Table where the keys are the keypad addresses 47 48 -- and the values are the partitions assigned to the keypads. 48 49 local g_noAddrPart = true -- True if one or more partitions have no associated keypads. 49 50 50 51 local g_partitions = { 51 52 -- device 52 -- address53 53 -- armMode 54 54 -- detailedArmMode 55 55 -- chimeMode 56 56 -- pinCode 57 } 58 59 local g_zones = { 60 -- device 61 -- name 57 62 } 58 63 … … 215 220 216 221 217 local function getPartitionNumber (id) 218 if (type (id) == "number") then -- The 'id' is the device number. 219 for k, v in pairs (g_partitions) do 220 if (id == v.device) then 221 return k 222 end 223 end 224 else -- The 'id' is the device altid. 225 local partNo = id:match ("vista_partition_(%d+)") 226 return tonumber (partNo, 10) 222 local function getPartitionNumber (deviceNo) 223 for k, v in pairs (g_partitions) do 224 if (deviceNo == v.device) then 225 return k 226 end 227 227 end 228 228 … … 313 313 function bypassZones (device, zones, pinCode) 314 314 315 debug (string.format ("(bypassZones) Bypass zones: %s, device #% s.", tostring (zones), tostring (device)))315 debug (string.format ("(bypassZones) Bypass zones: %s, device #%d.", tostring (zones), device)) 316 316 317 317 -- Check if the PIN code exists and is valid. … … 391 391 392 392 393 function setChimeMode (device, mode, pinCode) 394 debug (string.format ("(setChimeMode) Set chime mode to '%s' for device #%s.", tostring (mode), device)) 395 396 -- Check if the PIN code exists and is valid. 397 if (not pinCode) then 398 log ("(setChimeMode) ERROR: PIN code required.") 399 task ("PIN code required for changing the chime mode.", TASK.ERROR) 400 return false 401 elseif (not pinCode:match ("^%d%d%d%d$")) then 402 log ("(setChimeMode) ERROR: Invalid PIN code.") 403 task ("Invalid PIN code.", TASK.ERROR) 404 return false 405 end 406 407 -- Find the partition number. 408 local partNo = (g_nPartitions > 1) and getPartitionNumber (device) or 1 409 debug ("(setChimeMode) partNo = " .. partNo) 410 411 if (g_nPartitions > 1) then -- Send the GOTO command first. 412 local command = pinCode .. "*" .. partNo 413 luup.io.write (command) 414 luup.sleep (SLEEP_MS) 415 end 416 417 if (g_partitions[partNo].chimeMode ~= mode) then -- We're not already in the requested mode. 418 local command = pinCode .. "9" 419 luup.io.write (command) 420 end 421 422 -- Store the PIN code to be used for sending '*'. 423 g_partitions[partNo].pinCode = pinCode 424 425 return true 426 end 427 428 393 429 function storePinCode (device, pinCode) 394 430 … … 429 465 430 466 467 local function updateDevice (zone, tripped) 468 469 -- If a device for this zone doesn't exist, create it. 470 -- If it does, set Tripped = <tripped>. 471 if (not g_zones[zone]) then 472 g_zones[zone] = {} 473 local parameters = SID.SECURITY_SENSOR .. ",Armed=1\n" .. SID.SECURITY_SENSOR .. ",Tripped=" .. tripped 474 local ptr = luup.chdev.start (lug_device) 475 luup.chdev.append (lug_device, ptr, "vista_zone_" .. zone, "Vista Zone #" .. zone, "urn:schemas-micasaverde-com:device:MotionSensor:1", "D_MotionSensor1.xml", "", parameters, false) 476 luup.chdev.sync (lug_device, ptr) 477 else 478 luup.variable_set (SID.SECURITY_SENSOR, "Tripped", tripped, g_zones[zone].device) 479 end 480 end 481 482 431 483 local function addFaultedZone (zone) 432 484 if (not zone) then … … 435 487 end 436 488 437 local newZone = (not g_faultedZones[zone]) and true or false -- Check if this zone isn't already in the list.438 439 489 g_faultedZones[zone] = TTL -- Add or refresh the TTL. 440 490 debug (string.format ("(addFaultedZone) Zone %d TTL = %d", zone, g_faultedZones[zone])) 441 491 442 if (newZone) then -- Update this variable only if we have a new zone. 443 luup.variable_set (SID.PANEL, "FaultedZones", table.concatKeys (g_faultedZones, ","), lug_device) 444 debug ("(addFaultedZone) Added zone #" .. zone .. ".") 445 end 492 updateDevice (zone, "1") 446 493 end 447 494 … … 459 506 460 507 g_faultedZones[zone] = nil 461 462 local faultedZones = table.concatKeys (g_faultedZones, ",")463 if (faultedZones == "") then464 faultedZones = "none"465 end466 luup.variable_set (SID.PANEL, "FaultedZones", faultedZones, lug_device)467 468 508 debug ("(removeFaultedZone) Removed zone #" .. zone .. ".") 509 510 updateDevice (zone, "0") 469 511 end 470 512 … … 569 611 570 612 571 local function checkForAlarms (flags, partNo)613 local function checkForAlarms (flags, zone, partNo) 572 614 573 615 if (flags.FIRE_ALARM or flags.ALARM) then 574 local alarmText = flags.FIRE_ALARM and "FIRE ALARM!" or "ALARM!"575 log ("(checkForAlarms) " .. alarmText)576 task (alarmText, TASK.ERROR_PERM)577 578 616 local alarm = getPartitionState (partNo, "Alarm") 579 617 if (alarm ~= "Active") then 618 zone = tonumber (zone, 10) 619 local zoneInfo = string.format ("%s (device #%d, zone #%d)", g_zones[zone].name, g_zones[zone].device, zone) 620 local alarmInfo = flags.FIRE_ALARM and ("FIRE ALARM! " .. zoneInfo) or ("ALARM! " .. zoneInfo) 621 log ("(checkForAlarms) " .. alarmInfo) 622 task (alarmInfo, TASK.ERROR_PERM) 623 624 -- Add the faulted zone that caused the alarm to the list. 625 addFaultedZone (zone) 626 627 local alarmMemory = flags.ALARM_MEMORY and "1" or "0" 628 setPartitionState (partNo, "AlarmMemory", alarmMemory) 629 580 630 setPartitionState (partNo, "Alarm", "Active") 581 631 end 582 632 633 return true 634 end 635 636 local alarm = getPartitionState (partNo, "Alarm") 637 if (alarm ~= "None") then 638 setPartitionState (partNo, "Alarm", "None") 583 639 local alarmMemory = flags.ALARM_MEMORY and "1" or "0" 584 640 setPartitionState (partNo, "AlarmMemory", alarmMemory) 585 586 return true 587 else 588 local alarm = getPartitionState (partNo, "Alarm") 589 if (alarm ~= "None") then 590 setPartitionState (partNo, "Alarm", "None") 591 end 592 end 641 end 642 643 return false 593 644 end 594 645 … … 608 659 609 660 local debugString = "(getAddressBitMask) bitMask = " .. 610 611 612 613 661 table.concat (bitMask, "", 1, 8) .. " " .. 662 table.concat (bitMask, "", 9, 16) .. " " .. 663 table.concat (bitMask, "", 17, 24) .. " " .. 664 table.concat (bitMask, "", 25, 32) 614 665 debug (debugString) 615 666 return bitMask … … 721 772 for _, partNo in pairs (targetPartitions) do 722 773 -- Check if we have any alarms. 723 if (checkForAlarms (flags, partNo)) then774 if (checkForAlarms (flags, sections[2], partNo)) then 724 775 return false 725 776 end … … 747 798 748 799 749 local function getPartitionDevices() 800 local function getChildDevices() 801 750 802 for k, v in pairs (luup.devices) do 751 803 if (v.device_num_parent == lug_device) then 752 local partNo = getPartitionNumber (v.id) 753 if (partNo) then 754 debug (string.format ("(getPartitionDevices) Partition %d device number = %d", partNo, k)) 755 g_partitions[partNo] = {device = k} 756 else 757 log (string.format ("(getPartitionDevices) Found unexpected child: device #%d, id=%s", k, tostring (v.id))) 758 task (string.format ("Found unexpected child: device #%d, id=%s", k, tostring (v.id)), TASK.ERROR) 804 if (v.id:match ("^vista_zone") ~= nil) then -- The device is a zone. 805 local zoneNo = v.id:match ("^vista_zone_(%d+)$") 806 zoneNo = tonumber (zoneNo, 10) 807 g_zones[zoneNo].device = k 808 g_zones[zoneNo].name = v.description 809 debug (string.format ("(getChildDevices) Zone #%d device number = %d, name = %s", zoneNo, k, v.description)) 810 elseif (v.id:match ("^vista_partition") ~= nil) then -- The device is a partition. 811 local partNo = v.id:match ("^vista_partition_(%d+)$") 812 g_partitions[tonumber (partNo, 10)] = {device = k} 813 debug (string.format ("(getChildDevices) Partition %s device number = %d.", partNo, k)) 814 else -- Bastard child. 815 log (string.format ("(getChildDevices) Found unexpected child: device #%d, description = %s", k, tostring (v.description))) 816 task (string.format ("Found unexpected child: device #%d, name = %s", k, tostring (v.description)), TASK.ERROR) 759 817 end 760 818 end … … 848 906 luup.chdev.sync (lug_device, rootPtr) 849 907 850 get PartitionDevices()908 getChildDevices() 851 909 852 910 -- Get the partitions assigned to each keypad. … … 855 913 return false, message, "Ademco Vista Plugin" 856 914 end 857 858 luup.variable_set (SID.PANEL, "FaultedZones", "none", lug_device)859 915 860 916 -- Get the TTL.
Note: See TracChangeset
for help on using the changeset viewer.