def switches(self, switchesConfig): for switchConfig in switchesConfig: switch = Switch(self) if type(switchConfig) == dict or type(switchConfig) == OrderedDict: serial = switchConfig['serial'] name = switchConfig['name'] or 'switch-' + str(serial) elif type(switchConfig) == int: serial = switchConfig name = 'switch-' + str(serial) switch._name = name switch._serial = serial switch._serialAsBytes = Convert.intToBytes(serial, byteorder='little', length=4) self._appendDevice(switch)
def lights(self, lightsConfig): for lightConfig in lightsConfig: light = Light(self) if type(lightConfig) == dict or type(lightConfig) == OrderedDict: serial = lightConfig['serial'] name = lightConfig['name'] or 'lamp-' + str(serial) elif type(lightConfig) == int: serial = lightConfig name = 'lamp-' + str(serial) light._name = name light._serial = serial light._serialAsBytes = Convert.intToBytes(serial, byteorder='little', length=4) self._appendDevice(light) light.requestState()
def serial(self, value): self._serial = value self._serialAsBytes = Convert.intToBytes(value, byteorder="little", length=4)
def generate(data): crcData = bytes(data[3:-3]) crc = Crc.calc(crcData) data[-3:-1] = Convert.intToBytes(crc) return data
def setBrightness(self, serial, brightness): if brightness > 1: command = Convert.intToBytes(brightness, length=1) self._sendDimCommand(serial, command) else: self.setState(serial, False)