From 2ddc950bd34104f8543a7fa7b0c5586b4f8fc8e8 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sat, 6 Oct 2018 13:28:04 +0200 Subject: [PATCH] Clean up --- aiounifi/api.py | 14 +++++++++++++- aiounifi/controller.py | 1 - aiounifi/devices.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aiounifi/api.py b/aiounifi/api.py index da5c0fee48..61ca561bd6 100644 --- a/aiounifi/api.py +++ b/aiounifi/api.py @@ -1,3 +1,10 @@ +import logging + +from pprint import pformat + +LOGGER = logging.getLogger(__name__) + + class APIItems: """Base class for a map of API Items.""" @@ -7,6 +14,8 @@ def __init__(self, raw, request, path, item_cls): self._item_cls = item_cls self._items = {} self.process_raw(raw) + LOGGER.debug(pformat(raw)) + async def update(self): raw = await self._request('get', self._path) @@ -26,7 +35,10 @@ def values(self): return self._items.values() def __getitem__(self, obj_id): - return self._items[obj_id] + try: + return self._items[obj_id] + except KeyError: + LOGGER.error("Couldn't find key: '{}'".format(obj_id)) def __iter__(self): return iter(self._items) diff --git a/aiounifi/controller.py b/aiounifi/controller.py index bd9b383079..34075ffba2 100644 --- a/aiounifi/controller.py +++ b/aiounifi/controller.py @@ -65,5 +65,4 @@ async def request(self, method, path, json=None): def _raise_on_error(data): """Check response for error message.""" if isinstance(data, dict) and data['meta']['rc'] == 'error': - print('raise on error', data['meta']['msg']) raise_error(data['meta']['msg']) diff --git a/aiounifi/devices.py b/aiounifi/devices.py index 13c0bd2802..da3fec757c 100644 --- a/aiounifi/devices.py +++ b/aiounifi/devices.py @@ -1,4 +1,4 @@ -"""UniFi devices are hardware produced by Ubiquiti. +"""UniFi devices are network infrastructure. Access points, Gateways, Switches. """ @@ -62,7 +62,7 @@ def port_table(self): async def async_set_port_poe_mode(self, port_idx, mode): """Set port poe mode. - Auto, 24v, passthrough, off + Auto, 24v, passthrough, off. """ url = 's/{site}/rest/device/' + self.id data = {