Skip to content

Commit

Permalink
Add list-zones and prune-zones
Browse files Browse the repository at this point in the history
  • Loading branch information
kk7ds committed Dec 10, 2015
1 parent bdb8c82 commit 35fd0dd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,23 @@ def test_set_picture_settings_coerces(self):
json.dumps(
{'ispSettings': newvals_expected}))
self.assertEqual(fake_resp['data'][0]['ispSettings'], resp)

def test_get_zones(self):
fake_resp = {'data': [{'zones': ['fake-zone1',
'fake-zone2']}]}
client = nvr.UVCRemote('foo', 7080, 'key')
with mock.patch.object(client, '_uvc_request') as mock_r:
mock_r.return_value = fake_resp
resp = client.list_zones('uuid')
mock_r.assert_any_call('/api/2.0/camera/uuid')
self.assertEqual(fake_resp['data'][0]['zones'], resp)

def test_prune_zones(self):
fake_resp = {'data': [{'zones': ['fake-zone1',
'fake-zone2']}]}
client = nvr.UVCRemote('foo', 7080, 'key')
with mock.patch.object(client, '_uvc_request') as mock_r:
mock_r.return_value = fake_resp
resp = client.prune_zones('uuid')
mock_r.assert_any_call('/api/2.0/camera/uuid', 'PUT',
json.dumps({'zones': ['fake-zone1']}))
16 changes: 16 additions & 0 deletions uvcclient/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def main():
'returned from --get-picture-settings'))
parser.add_option('--set-led', default=None, metavar='ENABLED',
help='Enable/Disable front LED (on,off)')
parser.add_option('--prune-zones', default=None, action='store_true',
help='Prune all but the first motion zone')
parser.add_option('--list-zones', default=None, action='store_true',
help='List motion zones')
opts, args = parser.parse_args()

if not all([host, port, apikey]):
Expand Down Expand Up @@ -137,3 +141,15 @@ def main():
print 'Only micro cameras support LED status'
return 2
do_led(camera, opts.set_led.lower() == 'on')
elif opts.prune_zones:
if not opts.uuid:
print('Name or UUID is required')
return 1
client.prune_zones(opts.uuid)
elif opts.list_zones:
if not opts.uuid:
print('Name or UUID is required')
return 1
zones = client.list_zones(opts.uuid)
for zone in zones:
print(zone['name'])
11 changes: 11 additions & 0 deletions uvcclient/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ def set_picture_settings(self, uuid, settings):
data = self._uvc_request(url, 'PUT', json.dumps(data['data'][0]))
return data['data'][0]['ispSettings']

def prune_zones(self, uuid):
url = '/api/2.0/camera/%s' % uuid
data = self._uvc_request(url)
data['data'][0]['zones'] = [data['data'][0]['zones'][0]]
self._uvc_request(url, 'PUT', json.dumps(data['data'][0]))

def list_zones(self, uuid):
url = '/api/2.0/camera/%s' % uuid
data = self._uvc_request(url)
return data['data'][0]['zones']

def index(self):
"""Return an index of available cameras.
Expand Down

0 comments on commit 35fd0dd

Please sign in to comment.