Skip to content

Commit

Permalink
Merge pull request #51 from monty68/dev_v2
Browse files Browse the repository at this point in the history
Fix for early SP601E's
  • Loading branch information
monty68 authored Jan 22, 2024
2 parents 59ba3d6 + 8b28492 commit 3574a5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
34 changes: 21 additions & 13 deletions custom_components/uniled/lib/ble/banlanx_601.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,6 @@ def parse_notifications(

# Master Channel
#
input = None
loop = None
if len(data) > 0:
# 0 = Audio Input
# 1 = Auto Mode (0x00 = Off, 0x01 = On)
_LOGGER.debug("%s: Residual : %s", device.name, data.hex())
input = data[0] if self.model_num > 0x601E else None
loop = True if data[1] != 0 else False

last_save_scene = device.master.status.get(
ATTR_UL_SCENE_SAVE_SELECT, str(BANLANX601_MAX_SCENES)
)
Expand All @@ -374,24 +365,38 @@ def parse_notifications(
ATTR_UL_DEVICE_FORCE_REFRESH: True,
ATTR_UL_CHANNELS: channel_id,
ATTR_UL_POWER: True if master_power != 0 else False,
ATTR_HA_BRIGHTNESS: cast(int, master_level / channel_id),
ATTR_UL_SCENE: BANLANX601_MAX_SCENES,
ATTR_UL_SCENE_LOOP: loop,
# ATTR_UL_SCENE_SAVE_SELECT: last_save_scene,
# ATTR_UL_SCENE_SAVE_BUTTON: False,
}
)

level = cast(int, master_level / channel_id)
device.master.status.set(ATTR_HA_BRIGHTNESS, level)
if (timers := data.pop(0) if len(data) >= 1 else 0):
TIMER_DATA_SIZE = 7
timer_id = 0
while len(data) >= TIMER_DATA_SIZE and timer_id < timers:
timer_id += 1
timer_data = data[:TIMER_DATA_SIZE]
data = data[TIMER_DATA_SIZE:]
_LOGGER.debug(
"%s: Timer %s: %s",
device.name,
timer_id,
timer_data.hex(),
)

if (loop := data.pop(0) if len(data) >= 1 else None) is not None:
device.master.status.set(ATTR_UL_SCENE_LOOP, loop)

input = None
if input is not None and master_power:
audio_input = self.str_if_key_in(input, BANLANX601_AUDIO_INPUTS)
device.master.status.set(ATTR_UL_AUDIO_INPUT, audio_input)

if not device.master.features:
device.master.features = [
LightStripFeature(extra=UNILED_CONTROL_ATTRIBUTES),
SceneLoopFeature(),
# SceneSaveSelect(),
# SceneSaveButton(),
]
Expand All @@ -401,6 +406,9 @@ def parse_notifications(
SceneAttribute(b, UNILED_CONTROL_ATTRIBUTES)
)

if loop is not None:
device.master.features.append(SceneLoopFeature())

if input is not None:
device.master.features.append(AudioInputFeature())
return True
Expand Down
2 changes: 1 addition & 1 deletion custom_components/uniled/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"pycryptodome>=3.17",
"cryptography"
],
"version": "2.2.2"
"version": "2.2.3"
}

0 comments on commit 3574a5d

Please sign in to comment.