Skip to content

Commit

Permalink
Add mechanism to get device from key
Browse files Browse the repository at this point in the history
  • Loading branch information
gazoodle committed Dec 15, 2020
1 parent eb794fe commit c0d04a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/geckolib/automation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand All @@ -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})"
13 changes: 13 additions & 0 deletions src/geckolib/automation/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down

0 comments on commit c0d04a0

Please sign in to comment.