Skip to content

Commit

Permalink
Bugfix for getting rule ID by name
Browse files Browse the repository at this point in the history
Added extra check for rule ID
  • Loading branch information
laetificat committed Jan 19, 2019
1 parent 1e66a5d commit bbeeec2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build.sh
.DS_Store
*.pyc
__pycache__
/dist/
Expand Down
10 changes: 7 additions & 3 deletions haanna/haanna.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def get_domain_objects(self):
def get_presets(self, root):
"""Gets the presets from the thermostat"""
rule_id = self.get_rule_id_by_name(root, 'Thermostat presets')
if rule_id is None:
print("Could not find rule ID")
return
presets = self.get_preset_dictionary(root, rule_id)
return presets

Expand Down Expand Up @@ -125,9 +128,10 @@ def get_measurement_from_point_log(self, root, point_log_id):

def get_rule_id_by_name(self, root, rule_name):
"""Gets the rule ID based on name"""
current_rule = root.find("rule")
if current_rule.find("name").text == rule_name:
return current_rule.attrib['id']
rules = root.findall("rule")
for rule in rules:
if rule.find("name").text == rule_name:
return rule.attrib['id']

def get_preset_dictionary(self, root, rule_id):
"""Gets the presets from a rule based on rule ID and returns a dictionary with all the key-value pairs"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def readme():

setup(
name='haanna',
version='0.5.0',
version='0.5.1',
description='Plugwise Anna API to use in conjunction with Home Assistant.',
long_description='Plugwise Anna API to use in conjunction with Home Assistant, but it can also be used without Home Assistant.',
keywords='HomeAssistant HA Home Assistant Anna Plugwise',
Expand Down

0 comments on commit bbeeec2

Please sign in to comment.