Skip to content

Commit

Permalink
Burglar and other Active alarms now properly reported (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Dec 6, 2020
1 parent f806f88 commit 67f0342
Show file tree
Hide file tree
Showing 12 changed files with 1,862 additions and 65 deletions.
145 changes: 145 additions & 0 deletions tests/test_comnav_0_108_burglar_alarm_on.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 Chris Caron <[email protected]>
# All rights reserved.
#
# This code is licensed under the MIT License.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files(the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions :
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import mock
import requests
from os.path import join
from os.path import dirname

from ultrasync import UltraSync
from ultrasync.common import NX595EVendor

# Disable logging for a cleaner testing output
import logging
logging.disable(logging.CRITICAL)

# Reference Directory
ULTRASYNC_TEST_VAR_DIR = join(
dirname(__file__), 'var', NX595EVendor.COMNAV, '0.108-burglar-alarm-on')


@mock.patch('requests.Session.post')
def test_comnav_0_108_active_burglary(mock_post):
"""
Test ComNav v0.108 Hub Communication with Burglary in Progress
"""

# A area response object
arobj = mock.Mock()

# Simulate a valid login return
with open(join(ULTRASYNC_TEST_VAR_DIR, 'area.htm'), 'rb') as f:
arobj.content = f.read()
arobj.status_code = requests.codes.ok

# A zone response object
zrobj = mock.Mock()

# Simulate initial zone configuration
with open(join(ULTRASYNC_TEST_VAR_DIR, 'zones.htm'), 'rb') as f:
zrobj.content = f.read()
zrobj.status_code = requests.codes.ok

# A sequence response object
seq_obj = mock.Mock()

# Simulate initial sequence configuration
with open(join(ULTRASYNC_TEST_VAR_DIR, 'seq.xml'), 'rb') as f:
seq_obj.content = f.read()
seq_obj.status_code = requests.codes.ok

# A zone state response object
zst_obj = mock.Mock()

# Simulate initial zone fetch configuration
with open(join(ULTRASYNC_TEST_VAR_DIR, 'zstate.xml'), 'rb') as f:
zst_obj.content = f.read()
zst_obj.status_code = requests.codes.ok

# An area state response object
ast_obj = mock.Mock()

# Simulate initial area status fetch configuration
with open(join(ULTRASYNC_TEST_VAR_DIR, 'status.xml'), 'rb') as f:
ast_obj.content = f.read()
ast_obj.status_code = requests.codes.ok

# Assign our response object to our mocked instance of requests
mock_post.side_effect = (arobj, zrobj)

uobj = UltraSync()

# Perform a login which under the hood queries both area.htm and zones.htm
# (in that order)
assert uobj.login()
assert uobj.vendor is NX595EVendor.COMNAV
assert uobj.version == '0.108'
assert uobj.release == 'm'

assert isinstance(uobj.areas, dict)
# we only have 1 area defined in our test file
assert len(uobj.areas) == 1
assert uobj.areas[0]['name'] == 'Home'
assert uobj.areas[0]['bank'] == 0
assert uobj.areas[0]['sequence'] == 208
assert uobj.areas[0]['status'] == 'Burglar Alarm'

assert isinstance(uobj.zones, dict)
# our total zones defined
assert len(uobj.zones) == 17
zone_map = [
{
'bank': 0,
'name': 'MasterBed Motion',
}, {
'bank': 1,
'name': 'Living Room Motion',
}, {
'bank': 2,
'name': 'Kitchen/DiningMotion',
}, {
'bank': 3,
'name': 'Theater Motion',
}, {
'bank': 4,
'name': 'Hallway Motion',
}
]
for entry in zone_map:
assert entry['bank'] in uobj.zones
assert uobj.zones[entry['bank']]['bank'] == entry['bank']
assert uobj.zones[entry['bank']]['name'] == entry['name']
assert uobj.zones[entry['bank']]['sequence'] == 1
assert uobj.zones[entry['bank']]['status'] == \
entry.get('status', 'Ready')
assert uobj.zones[entry['bank']]['can_bypass'] is None

# A call to login.cgi (which fetches area.html) and then zones.htm
assert mock_post.call_count == 2
assert mock_post.call_args_list[0][0][0] == \
'http://zerowire/login.cgi'
assert mock_post.call_args_list[1][0][0] == \
'http://zerowire/user/zones.htm'
71 changes: 71 additions & 0 deletions tests/var/comnav/0.108-burglar-alarm-on/area.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>ComNav :: Secure Network</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width, maximum-scale = 1.0, minimum-scale = 1.0" />
<link href="/v_CN_0.108-m/m.css" rel="stylesheet">
<script src="/v_CN_0.108-m/master.js" charset="utf-8"></script>
<script src="/v_CN_0.108-m/status.js" charset="utf-8"></script>
<script src="/v_CN_0.108-m/lang_engau.js" charset="utf-8"></script>

</head>
<body onload = "afterLoad();">
<script>
var areaDisplay = new Array(0);


var areaNames = new Array("Home","%21","%21","%21","%21","%21","%21","%21");
var areaSequence = new Array(208);
var areaStatus = new Array(1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0);
var sysStatus;
var areaCount = 0;
var allAway = false;
var allStay = false;
var allChime = false;
var allpriority = 6;
var allSequence = 0;

function getSession(){return "E00BF6794F6D87DE";}
</script>

<div id="w">
<!-- buildBanner() inserts banner html here -->
<!-- buildMenu() inserts status menu here -->
<!-- buildAreas() inserts areas html here -->
</div>

<script>
sysStatus = new Array();

function afterLoad()
{
convertNames(areaNames);
hillsBuild = true;
variant = 3;
buildBanner("ComNav");
buildMenu(1,0,1,1,1,1);
buildAreas();

for(var i = (17*12); i < areaStatus.length;i++)
sysStatus.push(areaStatus[i]);
setTimeout("updateAllAreas()",1500);
areaSequence[0] += 100;
setTimeout("pollSequence()", 100);
}
// function called by iPhone to return "{active menu index, authorised menu list}"
// Note: the iPhone will display in the order presented here. see master.jss
function getMenu()
{
if(hillsBuild)
return "[0, [1,1,1,1,1,1,1,1,0,0,0,0,1]]";
else
if(variant == 1)
return "[0, [1,1,1,1,1,1,0,0,0,0,0,0,1]]";
else
return "[0, [1,1,1,1,1,1,0,1,0,0,0,0,1]]";
}

</script>
</body>
</html>
Loading

0 comments on commit 67f0342

Please sign in to comment.