Update only light changes
This commit is contained in:
parent
7bb470954a
commit
b77e4bed02
@ -1,6 +1,6 @@
|
|||||||
# AquaDMX
|
# AquaDMX
|
||||||
|
|
||||||
A custom DMX server that integrates with [Home Assistant](home-assistant.io).
|
A custom DMX server that integrates with [Home Assistant](https://home-assistant.io).
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
|
54
aquadmx.py
54
aquadmx.py
@ -11,10 +11,9 @@ from homeassistant_api.processing import process_json
|
|||||||
# Globals
|
# Globals
|
||||||
dataBuffer = []
|
dataBuffer = []
|
||||||
|
|
||||||
|
# Set Home Assistant Light based on DMX device and data.
|
||||||
def setLight(device, data):
|
def setLight(device, data):
|
||||||
start = device.getStartChannel()
|
start = device.getStartChannel()
|
||||||
print('{}'.format(device.getDeviceID()))
|
|
||||||
print(data[start], data[start+1], data[start+2], data[start+3])
|
|
||||||
if device.getLightType() == LightType.DIMMER:
|
if device.getLightType() == LightType.DIMMER:
|
||||||
light.turn_on(entity_id=device.getDeviceID(),
|
light.turn_on(entity_id=device.getDeviceID(),
|
||||||
brightness=data[start],
|
brightness=data[start],
|
||||||
@ -29,8 +28,8 @@ def setLight(device, data):
|
|||||||
def dmx_callback(data):
|
def dmx_callback(data):
|
||||||
global dataBuffer
|
global dataBuffer
|
||||||
if dataBuffer:
|
if dataBuffer:
|
||||||
diffs = [i[0] for i in enumerate(data) if data[i[0]] != dataBuffer[i[0]]]
|
diffs = [i[0]+1 for i in enumerate(data) if data[i[0]] != dataBuffer[i[0]]]
|
||||||
for d in u1.getDevices():
|
for d in u1.getDevicesByID(diffs):
|
||||||
setLight(d, data)
|
setLight(d, data)
|
||||||
else:
|
else:
|
||||||
# Set all lights on first
|
# Set all lights on first
|
||||||
@ -38,7 +37,7 @@ def dmx_callback(data):
|
|||||||
setLight(d, data)
|
setLight(d, data)
|
||||||
dataBuffer = data
|
dataBuffer = data
|
||||||
|
|
||||||
#
|
# Get a list of items in a config key
|
||||||
def configList(config, key):
|
def configList(config, key):
|
||||||
return [i.strip(' ') for i in config[key].split('\n')]
|
return [i.strip(' ') for i in config[key].split('\n')]
|
||||||
|
|
||||||
@ -49,12 +48,17 @@ def configOptionalList(config, key):
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# Types of Lights Supported.
|
||||||
class LightType(Enum):
|
class LightType(Enum):
|
||||||
DIMMER = 1
|
DIMMER = 1
|
||||||
RGB = 2
|
RGB = 2
|
||||||
|
|
||||||
|
# Data structure for a DMX Device.
|
||||||
class DMXDevice(object):
|
class DMXDevice(object):
|
||||||
|
|
||||||
startChannel = 0
|
startChannel = 0
|
||||||
|
|
||||||
|
# Initialize DMX Device.
|
||||||
def __init__(self, deviceID, lightType):
|
def __init__(self, deviceID, lightType):
|
||||||
self.deviceID = deviceID
|
self.deviceID = deviceID
|
||||||
self.lightType = lightType
|
self.lightType = lightType
|
||||||
@ -62,34 +66,65 @@ class DMXDevice(object):
|
|||||||
self.numChannels = 1
|
self.numChannels = 1
|
||||||
elif lightType is LightType.RGB:
|
elif lightType is LightType.RGB:
|
||||||
self.numChannels = 4
|
self.numChannels = 4
|
||||||
|
|
||||||
|
# Returns number of channels the device uses.
|
||||||
def getNumChannels(self):
|
def getNumChannels(self):
|
||||||
return self.numChannels
|
return self.numChannels
|
||||||
|
|
||||||
|
# Set the start channel for the device.
|
||||||
def setStartChannel(self, start):
|
def setStartChannel(self, start):
|
||||||
self.startChannel = start
|
self.startChannel = start
|
||||||
|
|
||||||
|
# Get the start channel for the device.
|
||||||
def getStartChannel(self):
|
def getStartChannel(self):
|
||||||
return self.startChannel
|
return self.startChannel
|
||||||
def getNumChannels(self):
|
|
||||||
return self.numChannels
|
# Get the end channel for the device.
|
||||||
|
def getEndChannel(self):
|
||||||
|
return self.startChannel+self.numChannels-1
|
||||||
|
|
||||||
|
# Get the type of light.
|
||||||
def getLightType(self):
|
def getLightType(self):
|
||||||
return self.lightType
|
return self.lightType
|
||||||
|
|
||||||
|
# Get the device ID for Home Assistant.
|
||||||
def getDeviceID(self):
|
def getDeviceID(self):
|
||||||
return self.deviceID
|
return self.deviceID
|
||||||
|
|
||||||
|
# Data structure for a DMX Universe.
|
||||||
class DMXUniverse(object):
|
class DMXUniverse(object):
|
||||||
|
|
||||||
maxChannels = 512
|
maxChannels = 512
|
||||||
|
|
||||||
|
# initialize DMX Universe.
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.channels = 1
|
self.channels = 1
|
||||||
self.devices = []
|
self.devices = []
|
||||||
|
|
||||||
|
# Add a device to the DMX Universe.
|
||||||
def addDevice(self, device):
|
def addDevice(self, device):
|
||||||
device.setStartChannel(self.channels)
|
device.setStartChannel(self.channels)
|
||||||
self.devices.append(device)
|
self.devices.append(device)
|
||||||
self.channels += device.getNumChannels()
|
self.channels += device.getNumChannels()
|
||||||
|
|
||||||
|
# Get channels in use in the DMX Universe.
|
||||||
def getChannels(self):
|
def getChannels(self):
|
||||||
return self.channels
|
return self.channels
|
||||||
|
|
||||||
|
# Get a list of devices in the DMX Universe.
|
||||||
def getDevices(self):
|
def getDevices(self):
|
||||||
return self.devices
|
return self.devices
|
||||||
|
|
||||||
|
# Get a list of device in the DMX Universe that match the given
|
||||||
|
# list of channels.
|
||||||
|
def getDevicesByID(self, channels):
|
||||||
|
l = []
|
||||||
|
for d in self.devices:
|
||||||
|
for c in channels:
|
||||||
|
if d.getStartChannel() <= c and c <= d.getEndChannel():
|
||||||
|
l.append(d)
|
||||||
|
return set(l)
|
||||||
|
|
||||||
# Configs
|
# Configs
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.sections()
|
config.sections()
|
||||||
@ -110,7 +145,6 @@ for l in dimmers:
|
|||||||
rgbs = configOptionalList(config['Lights'], 'rgb')
|
rgbs = configOptionalList(config['Lights'], 'rgb')
|
||||||
for l in rgbs:
|
for l in rgbs:
|
||||||
u1.addDevice(DMXDevice(l, LightType.RGB))
|
u1.addDevice(DMXDevice(l, LightType.RGB))
|
||||||
print(u1.getChannels())
|
|
||||||
|
|
||||||
# DMX
|
# DMX
|
||||||
universe = 1
|
universe = 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user