Lights set from config

This commit is contained in:
Christian Colglazier 2023-08-05 19:13:02 -04:00
parent b3da4aaaf3
commit b259cee0ce

View File

@ -8,16 +8,35 @@ from stupidArtnet import StupidArtnetServer
from homeassistant_api import Processing, Client
from homeassistant_api.processing import process_json
# Globals
dataBuffer = []
def setLight(device, data):
start = device.getStartChannel()
print('{}'.format(device.getDeviceID()))
print(data[start], data[start+1], data[start+2], data[start+3])
if device.getLightType() == LightType.DIMMER:
light.turn_on(entity_id=device.getDeviceID(),
brightness=data[start],
transition=0)
elif device.getLightType() == LightType.RGB:
light.turn_on(entity_id=device.getDeviceID(),
brightness=data[start],
transition=0,
rgb_color=[data[start+1], data[start+2], data[start+3]])
# DMX callback for changes to the universe.
def dmx_callback(data):
light.turn_on(entity_id='light.christian_s_bedroom_left_desk_lamp',
brightness=data[0],
transition=0,
rgb_color=[data[1], data[2], data[3]])
light.turn_on(entity_id='light.christian_s_bedroom_lamp_right',
brightness=data[4],
transition=0,
rgb_color=[data[5], data[6], data[7]])
global dataBuffer
if dataBuffer:
diffs = [i[0] for i in enumerate(data) if data[i[0]] != dataBuffer[i[0]]]
for d in u1.getDevices():
setLight(d, data)
else:
# Set all lights on first
for d in u1.getDevices():
setLight(d, data)
dataBuffer = data
#
def configList(config, key):
@ -47,8 +66,14 @@ class DMXDevice(object):
return self.numChannels
def setStartChannel(self, start):
self.startChannel = start
def getStartChannel(self):
return self.startChannel
def getNumChannels(self):
return self.numChannels
def getLightType(self):
return self.lightType
def getDeviceID(self):
return self.deviceID
class DMXUniverse(object):
@ -62,6 +87,8 @@ class DMXUniverse(object):
self.channels += device.getNumChannels()
def getChannels(self):
return self.channels
def getDevices(self):
return self.devices
# Configs
config = configparser.ConfigParser()