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 import Processing, Client
from homeassistant_api.processing import process_json 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. # DMX callback for changes to the universe.
def dmx_callback(data): def dmx_callback(data):
light.turn_on(entity_id='light.christian_s_bedroom_left_desk_lamp', global dataBuffer
brightness=data[0], if dataBuffer:
transition=0, diffs = [i[0] for i in enumerate(data) if data[i[0]] != dataBuffer[i[0]]]
rgb_color=[data[1], data[2], data[3]]) for d in u1.getDevices():
light.turn_on(entity_id='light.christian_s_bedroom_lamp_right', setLight(d, data)
brightness=data[4], else:
transition=0, # Set all lights on first
rgb_color=[data[5], data[6], data[7]]) for d in u1.getDevices():
setLight(d, data)
dataBuffer = data
# #
def configList(config, key): def configList(config, key):
@ -47,8 +66,14 @@ class DMXDevice(object):
return self.numChannels return self.numChannels
def setStartChannel(self, start): def setStartChannel(self, start):
self.startChannel = start self.startChannel = start
def getStartChannel(self):
return self.startChannel
def getNumChannels(self): def getNumChannels(self):
return self.numChannels return self.numChannels
def getLightType(self):
return self.lightType
def getDeviceID(self):
return self.deviceID
class DMXUniverse(object): class DMXUniverse(object):
@ -62,6 +87,8 @@ class DMXUniverse(object):
self.channels += device.getNumChannels() self.channels += device.getNumChannels()
def getChannels(self): def getChannels(self):
return self.channels return self.channels
def getDevices(self):
return self.devices
# Configs # Configs
config = configparser.ConfigParser() config = configparser.ConfigParser()
@ -77,7 +104,7 @@ light = client.get_domain('light')
# Lights # Lights
u1 = DMXUniverse() u1 = DMXUniverse()
dimmers =configOptionalList(config['Lights'], 'dimmer') dimmers = configOptionalList(config['Lights'], 'dimmer')
for l in dimmers: for l in dimmers:
u1.addDevice(DMXDevice(l, LightType.DIMMER)) u1.addDevice(DMXDevice(l, LightType.DIMMER))
rgbs = configOptionalList(config['Lights'], 'rgb') rgbs = configOptionalList(config['Lights'], 'rgb')