From c0d04a0c4dbddd891310292049c88ed468cdfadd Mon Sep 17 00:00:00 2001 From: gazoodle Date: Tue, 15 Dec 2020 15:22:40 +0000 Subject: [PATCH] Add mechanism to get device from key --- README.md | 2 ++ src/geckolib/automation/base.py | 8 ++++++++ src/geckolib/automation/facade.py | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 76d65e3..7751feb 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,8 @@ https://www.gnu.org/licenses/gpl-3.0.html ## Done/Fixed in 0.3.16 - More robust to missed packets during spa connection - Mechanism to access raw pack values from the facade, e.g. facade.pumps[0].state_sensor.accessor.raw_value + - Add API to facade to get device by key, e.g. facade.get_device("P1") will return the first pump. + - Add property to facade to get all device keys; facade.devices ## Done/Fixed in 0.3.15 - Trying out Github publish actions diff --git a/src/geckolib/automation/base.py b/src/geckolib/automation/base.py index 8cfd81f..f4fbf33 100644 --- a/src/geckolib/automation/base.py +++ b/src/geckolib/automation/base.py @@ -18,6 +18,11 @@ def name(self): """ All automation items have a name """ return self._name + @property + def key(self): + """ Key into the spa pack """ + return self._key + @property def unique_id(self): """ A unique id for the property """ @@ -27,3 +32,6 @@ def unique_id(self): def facade(self): """ Return the facade that is associated with this automation object """ return self._facade + + def __repr__(self): + return f"{super().__repr__()}(name={self.name}, key={self.key})" diff --git a/src/geckolib/automation/facade.py b/src/geckolib/automation/facade.py index 7db2c86..b74e7d3 100644 --- a/src/geckolib/automation/facade.py +++ b/src/geckolib/automation/facade.py @@ -250,6 +250,19 @@ def all_automation_devices(self): + [self.water_heater, self.water_care, self.keypad] ) + def get_device(self, key): + """ Get an automation device from the key """ + for device in self.all_automation_devices: + if device.key == key: + return device + return None + + @property + def devices(self): + """Get a list of automation device keys. Keys can be passed to get_device + to find the specific device""" + return [device.key for device in self.all_automation_devices] + @property def reminders(self): """ Get the reminders list """