diff --git a/src/discover_mihome.py b/src/discover_mihome.py index 107032b..124c283 100644 --- a/src/discover_mihome.py +++ b/src/discover_mihome.py @@ -16,7 +16,7 @@ print(message) y = raw_input(MSG) - except AttributeError: + except NameError: y = input(MSG) if y == "": return True diff --git a/src/energenie/Devices.py b/src/energenie/Devices.py index 9e9d5d6..78ba11d 100644 --- a/src/energenie/Devices.py +++ b/src/energenie/Devices.py @@ -3,9 +3,15 @@ # Information about specific Energenie devices # This table is mostly reverse-engineered from various websites and web catalogues. -from lifecycle import * -import OnAir -import OpenThings +##from lifecycle import * +try: + # Python 2 + import OnAir + import OpenThings +except ImportError: + # Python 3 + from . import OnAir + from . import OpenThings # This level of indirection allows easy mocking for testing ook_interface = OnAir.TwoBitAirInterface() diff --git a/src/energenie/Registry.py b/src/energenie/Registry.py index 5a46a3c..46a1a71 100644 --- a/src/energenie/Registry.py +++ b/src/energenie/Registry.py @@ -10,12 +10,13 @@ # Python 2 import Devices import OpenThings + from KVS import KVS except ImportError: # Python 3 from . import Devices from . import OpenThings + from .KVS import KVS -from KVS import KVS #----- NEW DEVICE REGISTRY ---------------------------------------------------- @@ -94,16 +95,21 @@ def devices(self): """A generator/iterator that can be used to get a list of device instances""" - # first get a list of all devices, in case the registry changes while iterating - devices = self.store.keys() - - # now 'generate' one per call - i = 0 - while i < len(devices): - k = devices[i] + # Python2 and Python3 safe + for k in self.store.keys(): device = self.store[k] yield device - i += 1 + + # first get a list of all devices, in case the registry changes while iterating + ##devices = self.store.keys() + + # now 'generate' one per call + ##i = 0 + ##while i < len(devices): + ## k = devices[i] + ## device = self.store[k] + ## yield device + ## i += 1 def names(self): """A generator/iterator that can be used to get a list of device names""" diff --git a/src/energenie/__init__.py b/src/energenie/__init__.py index e31e487..55267f5 100644 --- a/src/energenie/__init__.py +++ b/src/energenie/__init__.py @@ -10,17 +10,17 @@ import os try: - # Python 3 - from . import radio - from . import Devices - from . import Registry - from . import OpenThings -except ImportError: # Python 2 import radio import Devices import Registry import OpenThings +except ImportError: + # Python 3 + from . import radio + from . import Devices + from . import Registry + from . import OpenThings registry = None diff --git a/src/energenie/radio.py b/src/energenie/radio.py index ed0264d..56e08cb 100644 --- a/src/energenie/radio.py +++ b/src/energenie/radio.py @@ -12,8 +12,6 @@ # All you would need is a different radio.py that marshalled data to and from # the Arduino via pyserial. -from lifecycle import * - #TODO: Should really add parameter validation here, so that C code doesn't have to. #although it will be faster in C (C could be made optional, like an assert?)