Compare commits
No commits in common. "761683a046fc94c2a55de6dac7c5554110dd1dc3" and "53656b1f05ca63a7dc4967af1e6dada97ee3b224" have entirely different histories.
761683a046
...
53656b1f05
53
events.py
53
events.py
|
@ -195,46 +195,25 @@ async def neopixel(request, ws, data):
|
||||||
await ws.send_json(data)
|
await ws.send_json(data)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# TODO: form validation
|
||||||
|
|
||||||
mqtt_msg = [device.mqtt_root]
|
mqtt_msg = [device.mqtt_root]
|
||||||
if data.get('change_mode') == 'state':
|
mqtt_msg.append(data.get('change_mode'))
|
||||||
mqtt_msg.append(data.get('change_mode'))
|
mqtt_msg.append(data.get('type'))
|
||||||
if data.get('type') == 'solid':
|
if data.get('type') == 'solid':
|
||||||
mqtt_msg.append(data.get('type'))
|
mqtt_msg.append(data.get('amount'))
|
||||||
if data.get('amount') == 'single':
|
if data.get('amount') == 'single':
|
||||||
mqtt_msg.append(data.get('amount'))
|
mqtt_msg.append(data.get('sub_device_id').replace('led', ''))
|
||||||
mqtt_msg.append(data.get('sub_device_id').replace('led', ''))
|
|
||||||
elif data.get('amount') == 'all':
|
|
||||||
mqtt_msg.append(data.get('amount'))
|
|
||||||
else:
|
|
||||||
error = "invalid amount"
|
|
||||||
payload = tools.from_html_color(data.get('color'))
|
|
||||||
payload = str(payload)[1:-1].replace(' ', '')
|
|
||||||
elif data.get('type') == 'rainbow':
|
|
||||||
mqtt_msg.append(data.get('type'))
|
|
||||||
payload = ','.join(data.get('rainbow_params'))
|
|
||||||
elif data.get('type') == 'america':
|
|
||||||
mqtt_msg.append(data.get('type'))
|
|
||||||
payload = ','.join(data.get('america_params'))
|
|
||||||
else:
|
|
||||||
error = "invalid state type"
|
|
||||||
elif data.get('change_mode') == 'animation':
|
|
||||||
mqtt_msg.append(data.get('change_mode'))
|
|
||||||
if data.get('property_type') == 'mode':
|
|
||||||
mqtt_msg.append(data.get('property_type'))
|
|
||||||
if data.get('type') == 'static':
|
|
||||||
mqtt_msg.append(data.get('type'))
|
|
||||||
payload = ''
|
|
||||||
elif data.get('type') == 'rotate_left':
|
|
||||||
mqtt_msg.append(data.get('type'))
|
|
||||||
payload = data.get('rotate_count')
|
|
||||||
elif data.get('type') == 'rotate_right':
|
|
||||||
mqtt_msg.append(data.get('type'))
|
|
||||||
payload = data.get('rotate_count')
|
|
||||||
elif data.get('property_type') == 'delay':
|
|
||||||
mqtt_msg.append(data.get('property_type'))
|
|
||||||
payload = data.get('delay')
|
|
||||||
mqtt_msg = '/'.join(mqtt_msg)
|
mqtt_msg = '/'.join(mqtt_msg)
|
||||||
|
|
||||||
|
if data.get('type') == 'solid':
|
||||||
|
payload = tools.from_html_color(data.get('color'))
|
||||||
|
payload = str(payload)[1:-1].replace(' ', '')
|
||||||
|
elif data.get('type') == 'rainbow':
|
||||||
|
payload = ','.join(data.get('rainbow_params'))
|
||||||
|
elif data.get('type') == 'america':
|
||||||
|
payload = ','.join(data.get('america_params'))
|
||||||
|
|
||||||
request.app['mqtt'].publish(mqtt_msg, payload)
|
request.app['mqtt'].publish(mqtt_msg, payload)
|
||||||
# websocket response is handled under LightStrip.mqtt_callback
|
# websocket response is handled under LightStrip.mqtt_callback
|
||||||
|
|
||||||
|
|
27
models.py
27
models.py
|
@ -173,52 +173,29 @@ class LightStrip(Device):
|
||||||
data['change_mode'] = topic[1]
|
data['change_mode'] = topic[1]
|
||||||
|
|
||||||
if topic[1] == 'state':
|
if topic[1] == 'state':
|
||||||
|
data['type'] = topic[2]
|
||||||
if topic[2] == 'solid':
|
if topic[2] == 'solid':
|
||||||
data['type'] = topic[2]
|
|
||||||
payload = payload.split(',')
|
payload = payload.split(',')
|
||||||
payload = [int(num) for num in payload]
|
payload = [int(num) for num in payload]
|
||||||
|
data['amount'] = topic[3]
|
||||||
if topic[3] == 'single':
|
if topic[3] == 'single':
|
||||||
data['amount'] = topic[3]
|
|
||||||
data['sub_device_id'] = 'led' + topic[4]
|
data['sub_device_id'] = 'led' + topic[4]
|
||||||
|
|
||||||
sub_device = self.find('led' + topic[4])
|
sub_device = self.find('led' + topic[4])
|
||||||
sub_device.color = payload
|
sub_device.color = payload
|
||||||
elif topic[3] == 'all':
|
elif topic[3] == 'all':
|
||||||
data['amount'] = topic[3]
|
|
||||||
for sub_device in self.sub_devices:
|
for sub_device in self.sub_devices:
|
||||||
sub_device.color = payload
|
sub_device.color = payload
|
||||||
data['color'] = tools.to_html_color(payload)
|
data['color'] = tools.to_html_color(payload)
|
||||||
elif topic[2] == 'rainbow':
|
elif topic[2] == 'rainbow':
|
||||||
data['type'] = topic[2]
|
|
||||||
payload = payload.split(',')
|
payload = payload.split(',')
|
||||||
self.rainbow_params = [float(p) for p in payload[:3]]
|
self.rainbow_params = [float(p) for p in payload[:3]]
|
||||||
self.rainbow_params += [int(p) for p in payload[3:]]
|
self.rainbow_params += [int(p) for p in payload[3:]]
|
||||||
data['rainbow_params'] = self.rainbow_params
|
data['rainbow_params'] = self.rainbow_params
|
||||||
elif topic[2] == 'america':
|
elif topic[2] == 'america':
|
||||||
data['type'] = topic[2]
|
|
||||||
payload = payload.split(',')
|
payload = payload.split(',')
|
||||||
self.america_params = [int(n) for n in payload]
|
self.america_params = [int(n) for n in payload]
|
||||||
data['america_params'] = self.america_params
|
data['america_params'] = self.america_params
|
||||||
elif topic[1] == 'animation':
|
|
||||||
if topic[2] == 'mode':
|
|
||||||
data['property_type'] = topic[2]
|
|
||||||
if topic[3] == 'static':
|
|
||||||
data['type'] = topic[3]
|
|
||||||
self.animation = topic[3]
|
|
||||||
elif topic[3] == 'rotate_left':
|
|
||||||
data['type'] = topic[3]
|
|
||||||
data['rotate_count'] = payload
|
|
||||||
self.animation = topic[3]
|
|
||||||
self.animation_rotate_count = int(payload)
|
|
||||||
elif topic[3] == 'rotate_right':
|
|
||||||
data['type'] = topic[3]
|
|
||||||
data['rotate_count'] = payload
|
|
||||||
self.animation = topic[3]
|
|
||||||
self.animation_rotate_count = int(payload)
|
|
||||||
elif topic[2] == 'delay':
|
|
||||||
data['property_type'] = topic[2]
|
|
||||||
data['delay'] = payload
|
|
||||||
self.animation_delay = int(payload)
|
|
||||||
elif topic[1] == 'strip':
|
elif topic[1] == 'strip':
|
||||||
data['amount'] = topic[2]
|
data['amount'] = topic[2]
|
||||||
if topic[2] == 'full':
|
if topic[2] == 'full':
|
||||||
|
|
|
@ -305,32 +305,6 @@ function neopixel_state(device) {
|
||||||
socket.send('neopixel', data);
|
socket.send('neopixel', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function neopixel_animation(device) {
|
|
||||||
let property_type;
|
|
||||||
if (device.nodeName === 'INPUT') {
|
|
||||||
property_type = 'delay';
|
|
||||||
device = device.closest('.device');
|
|
||||||
} else {
|
|
||||||
property_type = 'mode';
|
|
||||||
}
|
|
||||||
let data = {
|
|
||||||
device_id: device.id,
|
|
||||||
change_mode: 'animation',
|
|
||||||
property_type: property_type
|
|
||||||
}
|
|
||||||
if (property_type === 'mode') {
|
|
||||||
let animation_mode = device.querySelector('.animation_select').value;
|
|
||||||
data['type'] = animation_mode;
|
|
||||||
if (animation_mode === 'static') {
|
|
||||||
} else if (animation_mode === 'rotate_left' || animation_mode === 'rotate_right') {
|
|
||||||
data['rotate_count'] = device.querySelector('#animation_rotate_count_' + device.id).value;
|
|
||||||
}
|
|
||||||
} else if (property_type === 'delay') {
|
|
||||||
data['delay'] = device.querySelector('#animation_delay_' + device.id).value;
|
|
||||||
}
|
|
||||||
socket.send('neopixel', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DOM */
|
/* DOM */
|
||||||
function edit_field(field) {
|
function edit_field(field) {
|
||||||
let value = field.firstElementChild.innerText;
|
let value = field.firstElementChild.innerText;
|
||||||
|
@ -364,7 +338,8 @@ function state_solid_amount(radio) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function state_select(select) {
|
function state_select(select) {
|
||||||
let device = select.closest('.device');
|
let device = select.parentElement.parentElement.parentElement;
|
||||||
|
let sub_devices = device.querySelector('.sub_devices');
|
||||||
if (select.value === 'solid') {
|
if (select.value === 'solid') {
|
||||||
select.parentElement.querySelector('.state_solid').style.display = 'block';
|
select.parentElement.querySelector('.state_solid').style.display = 'block';
|
||||||
select.parentElement.querySelector('.state_rainbow').style.display = 'none';
|
select.parentElement.querySelector('.state_rainbow').style.display = 'none';
|
||||||
|
@ -373,29 +348,19 @@ function state_select(select) {
|
||||||
select.parentElement.querySelector('.state_solid').style.display = 'none';
|
select.parentElement.querySelector('.state_solid').style.display = 'none';
|
||||||
select.parentElement.querySelector('.state_rainbow').style.display = 'block';
|
select.parentElement.querySelector('.state_rainbow').style.display = 'block';
|
||||||
select.parentElement.querySelector('.state_america').style.display = 'none';
|
select.parentElement.querySelector('.state_america').style.display = 'none';
|
||||||
|
for (let sub_device of sub_devices.children) {
|
||||||
|
let input = sub_device.firstElementChild.firstElementChild;
|
||||||
|
input.disabled = true;
|
||||||
|
}
|
||||||
} else if (select.value === 'america') {
|
} else if (select.value === 'america') {
|
||||||
select.parentElement.querySelector('.state_solid').style.display = 'none';
|
select.parentElement.querySelector('.state_solid').style.display = 'none';
|
||||||
select.parentElement.querySelector('.state_rainbow').style.display = 'none';
|
select.parentElement.querySelector('.state_rainbow').style.display = 'none';
|
||||||
select.parentElement.querySelector('.state_america').style.display = 'block';
|
select.parentElement.querySelector('.state_america').style.display = 'block';
|
||||||
|
for (let sub_device of sub_devices.children) {
|
||||||
|
let input = sub_device.firstElementChild.firstElementChild;
|
||||||
|
input.disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let sub_devices = device.querySelector('.sub_devices');
|
|
||||||
for (let sub_device of sub_devices.children) {
|
|
||||||
let input = sub_device.firstElementChild.firstElementChild;
|
|
||||||
input.disabled = true;
|
|
||||||
}
|
|
||||||
neopixel_state(device);
|
|
||||||
}
|
|
||||||
|
|
||||||
function animation_select(select) {
|
|
||||||
let device = select.closest('.device');
|
|
||||||
if (select.value === 'static') {
|
|
||||||
select.parentElement.querySelector('.animation_static').style.display = 'block';
|
|
||||||
select.parentElement.querySelector('.animation_rotate').style.display = 'none';
|
|
||||||
} else if (select.value === 'rotate_left' || select.value === 'rotate_right') {
|
|
||||||
select.parentElement.querySelector('.animation_static').style.display = 'none';
|
|
||||||
select.parentElement.querySelector('.animation_rotate').style.display = 'block';
|
|
||||||
}
|
|
||||||
neopixel_animation(device);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
|
|
|
@ -115,20 +115,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="animation">
|
<div class="animation">
|
||||||
<span>Animation</span><br>
|
<span>Animation</span><br>
|
||||||
<select class="animation_select" onchange="animation_select(this)">
|
<select>
|
||||||
<option{% if device.animation == 'static' %} checked{% endif %} value="static">Static</option>
|
<option>Static</option>
|
||||||
<option{% if device.animation == 'rotate_left' %} checked{% endif %} value="rotate_left">Rotate Left</option>
|
<option>Rotate Left</option>
|
||||||
<option{% if device.animation == 'rotate_right' %} checked{% endif %} value="rotate_right">Rotate Right</option>
|
<option>Rotate Right</option>
|
||||||
</select>
|
</select>
|
||||||
<div class="animation_static" style="display: {% if device.animation == 'static' %}block{% else %}none{% endif %}">
|
|
||||||
</div>
|
|
||||||
<div class="animation_rotate" style="display: {% if device.animation == 'rotate_left' or device.animation == 'rotate_right' %}block{% else %}none{% endif %}">
|
|
||||||
<label for="animation_rotate_count_{{ device.id }}">Rotate Count</label>
|
|
||||||
<input type="number" id="animation_rotate_count_{{ device.id }}" min="1" max="255" step="1" value="{{ device.animation_rotate_count }}" onchange="neopixel_animation(this.closest('.device'))">
|
|
||||||
</div>
|
|
||||||
Delay
|
|
||||||
<input type="number" id="animation_delay_{{ device.id }}" min="1" max="255" step="1" value="{{ device.animation_delay }}" onchange="neopixel_animation(this)">
|
|
||||||
<label for="animation_delay{{ device.id }}">ms</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user