diff --git a/tests/test_client.py b/tests/test_client.py index c605f0e..8d4c0fa 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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']})) diff --git a/uvcclient/main.py b/uvcclient/main.py index d18453f..5ac830e 100644 --- a/uvcclient/main.py +++ b/uvcclient/main.py @@ -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]): @@ -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']) diff --git a/uvcclient/nvr.py b/uvcclient/nvr.py index 219a94a..04d64bd 100755 --- a/uvcclient/nvr.py +++ b/uvcclient/nvr.py @@ -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.