Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene fixes #234

Merged
merged 14 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions insteon_mqtt/Scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def compress_controllers(self):
controllers are merged.

This is a companion to compress_responders and compress_n_way. These
are seperate functions to that they can be called seperately using
are seperate functions so that they can be called seperately using
Stacks.

This function only processes the scenes in a single pass. If it runs
Expand Down Expand Up @@ -164,7 +164,7 @@ def compress_responders(self):
merged.

This is a companion to compress_controllers and compress_n_way.
These are seperate functions to that they can be called seperately
These are seperate functions so that they can be called seperately
using Stacks.

This function only processes the scenes in a single pass. If it runs
Expand Down Expand Up @@ -205,7 +205,7 @@ def compress_n_way(self):
definition..

This is a companion to compress_responders and compress_controllers.
These are seperate functions to that they can be called seperately
These are seperate functions so that they can be called seperately
using Stacks.

This function only processes the scenes in a single pass. If it runs
Expand Down Expand Up @@ -522,7 +522,7 @@ def from_link_entry(scene_manager, device, entry):
if not found_ctrl:
# We know nothing about the controller so set to default values
# the link-data may be wrong, but it doesn't seem to matter
if entry.group > 0x01:
if entry.group != 0x01:
scene['controllers'].append({entry_addr: entry.group})
else:
scene['controllers'].append(entry_addr)
Expand Down Expand Up @@ -731,16 +731,13 @@ def __eq__(self, other):
primarily by the compress_* functions
'''
ret = False
self_group = self.group if self.group > 0x00 else 0x01
other_group = other.group if other.group > 0x00 else 0x01
if (self.addr == other.addr and self_group == other_group and
if (self.addr == other.addr and self.group == other.group and
self.link_data == other.link_data):
ret = True
return ret

def __str__(self):
self_group = self.group if self.group > 0x00 else 0x01
subs = (self.addr, self_group, self.link_data)
subs = (self.addr, self.group, self.link_data)
return 'Dev Addr: %s Group: %s Data1-3: %s' % subs

def __hash__(self):
Expand Down Expand Up @@ -822,20 +819,20 @@ def group(self, value):
Args:
value: (int)The group value
"""
if self.style == 0 and value > 0x01:
if self.style == 0 and value != 0x01:
if ('group' not in self._yaml_data[self.label] or
self._yaml_data[self.label]['group'] != value):
self._yaml_data[self.label]['group'] = value
if self.style == 1 and value > 0x01:
if self.style == 1 and value != 0x01:
self._yaml_data[self.label] = value
if self.style == 2 and value > 0x01:
if self.style == 2 and value != 0x01:
self._yaml_data = {self.label: value}

# Remove group entry in yaml_data if default value of 0x00 or 0x01
# Remove group entry in yaml_data if default value of 0x01
if (self.style == 0 and 'group' in self._yaml_data[self.label] and
value <= 0x01):
value == 0x01):
del self._yaml_data[self.label]['group']
elif self.style == 1 and value <= 0x01:
elif self.style == 1 and value == 0x01:
self._yaml_data = self.label
self.update_device()

Expand Down Expand Up @@ -891,7 +888,7 @@ def link_data(self):
# Group is a bit special and gets added to link_data
# a few responders (kpl) need to know group to set data_3
link_dict = self._yaml_data[self.label].copy()
if self.group > 0x01:
if self.group != 0x01:
link_dict['group'] = self.group
# Convert data values from human readable form
pretty_data = self.device.link_data_from_pretty(
Expand Down
3 changes: 2 additions & 1 deletion insteon_mqtt/db/Device.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ def diff(self, rhs):

delta = DbDiff(self.addr)
for entry in self.entries.values():
rhsEntry = rhs.find(entry.addr, entry.group, entry.is_controller)
rhsEntry = rhs.find(entry.addr, entry.group, entry.is_controller,
entry.data[2])

# RHS is missing this entry or has different data bytes we need
# to update.
Expand Down
4 changes: 2 additions & 2 deletions insteon_mqtt/device/Dimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ def link_data_from_pretty(self, is_controller, data):
if 'data_3' in data:
data_3 = data['data_3']
if not is_controller:
if 'ramp' in data:
if 'ramp_rate' in data:
data_2 = 0x1f
for ramp_key, ramp_value in self.ramp_pretty.items():
if data['ramp'] >= ramp_value:
if data['ramp_rate'] >= ramp_value:
data_2 = ramp_key
break
if 'on_level' in data:
Expand Down
11 changes: 6 additions & 5 deletions insteon_mqtt/device/FanLinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,12 @@ def link_data_from_pretty(self, is_controller, data):
if not is_controller:
if 'group' in data:
data_3 = data['group']
if 'ramp' in data and data['group'] <= 0x01:
data_2 = 0x1f
for ramp_key, ramp_value in Dimmer.ramp_pretty:
if data['ramp'] >= ramp_value:
data_2 = ramp_key
if 'ramp_rate' in data and (data_3 is None or data_3 == 0x01):
tstabrawa marked this conversation as resolved.
Show resolved Hide resolved
data_2 = 0x1f
for ramp_key, ramp_value in Dimmer.ramp_pretty.items():
if data['ramp_rate'] >= ramp_value:
data_2 = ramp_key
break
if 'on_level' in data:
data_1 = int(data['on_level'] * 2.55 + .5)
return [data_1, data_2, data_3]
Expand Down
7 changes: 4 additions & 3 deletions insteon_mqtt/device/KeypadLinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,12 @@ def link_data_from_pretty(self, is_controller, data):
if 'group' in data:
data_3 = data['group']
if not is_controller and self.is_dimmer:
if 'ramp' in data:
if 'ramp_rate' in data:
data_2 = 0x1f
for ramp_key, ramp_value in Dimmer.ramp_pretty:
if data['ramp'] >= ramp_value:
for ramp_key, ramp_value in Dimmer.ramp_pretty.items():
if data['ramp_rate'] >= ramp_value:
data_2 = ramp_key
break
if 'on_level' in data:
data_1 = int(data['on_level'] * 2.55 + .5)
return [data_1, data_2, data_3]
Expand Down
7 changes: 2 additions & 5 deletions insteon_mqtt/device/Remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ def link_data(self, is_controller, group, data=None):
Returns:
bytes[3]: Returns a list of 3 bytes to use as D1,D2,D3.
"""
# Most of this is from looking through Misterhouse bug reports.
if is_controller:
defaults = [0x03, 0x00, group]
defaults = [0x03, 0x00, 0x00]

# Responder data is always link dependent. Since nothing was given,
# assume the user wants to turn the device on (0xff).
Expand All @@ -224,7 +223,7 @@ def link_data_to_pretty(self, is_controller, data):
Returns:
list[3]: list, containing a dict of the human readable values
"""
ret = [{'data_1': data[0]}, {'data_2': data[1]}, {'group': data[2]}]
ret = [{'data_1': data[0]}, {'data_2': data[1]}, {'data_3': data[2]}]
return ret

#-----------------------------------------------------------------------
Expand All @@ -251,8 +250,6 @@ def link_data_from_pretty(self, is_controller, data):
data_3 = None
if 'data_3' in data:
data_3 = data['data_3']
if 'group' in data:
data_3 = data['group']
return [data_1, data_2, data_3]

#-----------------------------------------------------------------------
Loading