From d41ea366e7c2e51c9f7e68092d89e3f0be580362 Mon Sep 17 00:00:00 2001 From: Ruben Undheim Date: Fri, 21 Dec 2018 21:01:06 +0100 Subject: Import python-netdisco_2.2.0.orig.tar.gz [dgit import orig python-netdisco_2.2.0.orig.tar.gz] --- netdisco/discoverables/axis.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 netdisco/discoverables/axis.py (limited to 'netdisco/discoverables/axis.py') diff --git a/netdisco/discoverables/axis.py b/netdisco/discoverables/axis.py new file mode 100644 index 0000000..c4278b1 --- /dev/null +++ b/netdisco/discoverables/axis.py @@ -0,0 +1,41 @@ +"""Discover Axis devices.""" +from . import MDNSDiscoverable + +from ..const import ( + ATTR_HOST, ATTR_PORT, ATTR_HOSTNAME, ATTR_PROPERTIES) + + +class Discoverable(MDNSDiscoverable): + """Add support for discovering Axis devices.""" + + def info_from_entry(self, entry): + """Return most important info from mDNS entries.""" + properties = {} + + for key, value in entry.properties.items(): + if isinstance(value, bytes): + value = value.decode('utf-8') + properties[key.decode('utf-8')] = value + + return { + ATTR_HOST: self.ip_from_host(entry.server), + ATTR_PORT: entry.port, + ATTR_HOSTNAME: entry.server, + ATTR_PROPERTIES: properties, + } + + def __init__(self, nd): + """Initialize the Axis discovery.""" + super(Discoverable, self).__init__(nd, '_axis-video._tcp.local.') + + def ip_from_host(self, host): + """Attempt to return the ip address from an mDNS host. + + Return host if failed. + """ + ips = self.netdis.mdns.zeroconf.cache.entries_with_name(host.lower()) + + try: + return repr(ips[0]) if ips else host + except TypeError: + return host -- cgit v1.2.3