def parseSensor(data, device): value = Convert.bytesToDecimal(data[21:22]) state = Convert.bytesToInt(data[24:25]) == 255 device.value = value device.state = state return device
def parseSensor(self, data, device): value = Convert.bytesToDecimal(data[21:22]) state = Convert.bytesToInt(data[24:25]) == 255 device._state = state device._value = value device._runCallbacks() return device
def parseLight(data, device): stateValue = Convert.bytesToInt(data[22:23]) state = True if stateValue == 3: device.isDimable = False if stateValue < 3: state = False device.silentBrightness = stateValue device.silentState = state return device
def parseLight(self, data, device): stateValue = Convert.bytesToInt(data[22:23]) state = True if (stateValue == 3): device._isDimable = False if stateValue < 3: state = False device._state = state device._brightness = stateValue device._runCallbacks() return device
def parseSerial(byteArray, device): deviceType = type(device) if deviceType == Switch: serialAsBytes = byteArray[10:14] elif deviceType == Sensor: serialAsBytes = byteArray[15:19] elif deviceType == Light: serialAsBytes = byteArray[10:14] serial = Convert.bytesToInt(serialAsBytes, byteorder="big") # device.serialAsBytes = serialAsBytes device.serial = serial return device
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 parseSerial(self, byteArray, device): deviceType = type(device) if deviceType == Switch: bytes = byteArray[10:14] elif deviceType == Sensor: bytes = byteArray[15:19] elif deviceType == Light: bytes = byteArray[10:14] serial = Convert.bytesToInt(bytes, byteorder='big') device._serialAsBytes = bytes device._serial = serial return serial
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 test_bytesToInt(self): data = bytearray(b"\xc5\xc4\x55\x00") ints = Convert.bytesToInt(data) self.assertEqual(5620933, ints)
def test_bytesToDecimal(self): data = bytearray(b"\xd5") ints = Convert.bytesToDecimal(data) self.assertEqual(21.3, ints)
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)