def level(self, value): if not self.min_level <= value <= self.max_level and value != 0: raise ValueError self.__level = value self.driver.send(gear.DAPC(self.short_address, self.level)) logger.debug("Set lamp <%s> brightness level to %s", self.friendly_name, self.level)
def on_message_brightness_cmd(mosq, dalic, msg): logger.debug("Brightness Command on %s: %s", msg.topic, msg.payload) light = int( re.search( MQTT_BRIGHTNESS_COMMAND_TOPIC.format(MQTT_BASE_TOPIC, '(.+?)'), msg.topic).group(1)) try: level = int(msg.payload.decode("utf-8")) if not 0 <= level <= 255: raise ValueError logger.debug("Set light <%s> brightness to %s", light, level) r = dalic.send(gear.DAPC(address.Short(light), level)) if level == 0: # 0 in DALI is turn off with fade out mosq.publish(MQTT_STATE_TOPIC.format(MQTT_BASE_TOPIC, light), MQTT_PAYLOAD_OFF, retain=True) else: mosq.publish(MQTT_STATE_TOPIC.format(MQTT_BASE_TOPIC, light), MQTT_PAYLOAD_ON, retain=True) mosq.publish(MQTT_BRIGHTNESS_STATE_TOPIC.format( MQTT_BASE_TOPIC, light), level, retain=True) except ValueError as e: logger.error("Can't convert <%s> to interger 0..255: %s", level, e)
def test_with_integer_destination(self): """commands accept integer destination""" self.assertEqual( generalgear.DAPC(5, 100).destination, address.Short(5)) self.assertEqual(generalgear.Off(5).destination, address.Short(5)) self.assertRaises(ValueError, generalgear.Off, -1) self.assertRaises(ValueError, generalgear.Off, 64) self.assertRaises(ValueError, generalgear.Off, None)
def send(self, command, address, data, data2=None): '''Function to send DALI commands. ''' if command == commands['-']: main_command = gear.DAPC(address, data) self._interface.send(main_command) elif command == commands[0x00]: main_command = gear.Off(address) self._interface.send(main_command) elif command == commands[0x01]: main_command = gear.Up(address) self._interface.send(main_command) elif command == commands[0x02]: main_command = gear.Down(address) self._interface.send(main_command) elif command == commands[0x03]: main_command = gear.StepUp(address) self._interface.send(main_command) elif command == commands[0x04]: main_command = gear.StepDown(address) self._interface.send(main_command) elif command == commands[0x05]: main_command = gear.RecallMaxLevel(address) self._interface.send(main_command) elif command == commands[0x06]: main_command = gear.RecallMinLevel(address) self._interface.send(main_command) elif command == commands[0x07]: main_command = gear.StepDownAndOff(address) self._interface.send(main_command) elif command == commands[0x08]: main_command = gear.OnAndStepUp(address) self._interface.send(main_command) elif command == commands[0x09]: main_command = gear.EnableDAPCSequence(address) self._interface.send(main_command) elif command == commands[0x0A]: main_command = gear.GoToLastActiveLevel(address) self._interface.send(main_command) elif command == commands[0x0B]: main_command = gear.ContinuousUp(address) self._interface.send(main_command) elif command == commands[0x0C]: main_command = gear.ContinuousDown(address) self._interface.send(main_command) elif command == commands[0x10]: main_command = gear.GoToScene(address, data) self._interface.send(main_command) elif command == commands[0x20]: main_command = gear.Reset(address) self._interface.send(main_command) elif command == commands[0x21]: main_command = gear.StoreActualLevelInDTR0(address) self._interface.send(main_command) elif command == commands[0x22]: main_command = gear.SavePersistentVariables(address) self._interface.send(main_command) elif command == commands[0x23]: self._interface.send(gear.DTR0(data)) main_command = gear.SetOperatingMode(address) self._interface.send(main_command) elif command == commands[0x24]: self._interface.send(gear.DTR0(data)) main_command = gear.ResetMemoryBank(address) self._interface.send(main_command) elif command == commands[0x25]: main_command = gear.IdentifyDevice(address) self._interface.send(main_command) elif command == commands[0x2A]: self._interface.send(gear.DTR0(data)) main_command = gear.SetMaxLevel(address) self._interface.send(main_command) elif command == commands[0x2B]: self._interface.send(gear.DTR0(data)) main_command = gear.SetMinLevel(address) self._interface.send(main_command) elif command == commands[0x2C]: self._interface.send(gear.DTR0(data)) main_command = gear.SetSystemFailureLevel(address) self._interface.send(main_command) elif command == commands[0x2D]: self._interface.send(gear.DTR0(data)) main_command = gear.SetPowerOnLevel(address) self._interface.send(main_command) elif command == commands[0x2E]: self._interface.send(gear.DTR0(data)) main_command = gear.SetFadeTime(address) self._interface.send(main_command) elif command == commands[0x2F]: self._interface.send(gear.DTR0(data)) main_command = gear.SetFadeRate(address) self._interface.send(main_command) elif command == commands[0x30]: self._interface.send(gear.DTR0(data)) main_command = gear.SetExtendedFadeTime(address) self._interface.send(main_command) elif command == commands[0x40]: self._interface.send(gear.DTR0(data2)) main_command = gear.SetScene(address, data) self._interface.send(main_command) elif command == commands[0x50]: main_command = gear.RemoveFromScene(address, data) self._interface.send(main_command) elif command == commands[0x60]: main_command = gear.AddToGroup(address, data) self._interface.send(main_command) elif command == commands[0x70]: main_command = gear.RemoveFromGroup(address, data) self._interface.send(main_command) elif command == commands[0x80]: self._interface.send(gear.DTR0(data)) main_command = gear.SetShortAddress(address) self._interface.send(main_command) elif command == commands[0x81]: main_command = gear.EnableWriteMemory(address) self._interface.send(main_command) elif command == commands[0x90]: main_command = gear.QueryStatus(address) self._interface.send(main_command) elif command == commands[0x91]: main_command = gear.QueryControlGearPresent(address) self._interface.send(main_command) elif command == commands[0x92]: main_command = gear.QueryLampFailure(address) self._interface.send(main_command) elif command == commands[0x93]: main_command = gear.QueryLampPowerOn(address) self._interface.send(main_command) elif command == commands[0x94]: main_command = gear.QueryLimitError(address) self._interface.send(main_command) elif command == commands[0x95]: main_command = gear.QueryResetState(address) self._interface.send(main_command) elif command == commands[0x96]: main_command = gear.QueryMissingShortAddress(address) self._interface.send(main_command) elif command == commands[0x97]: main_command = gear.QueryVersionNumber(address) self._interface.send(main_command) elif command == commands[0x98]: main_command = gear.QueryContentDTR0(address) self._interface.send(main_command) elif command == commands[0x99]: main_command = gear.QueryDeviceType(address) self._interface.send(main_command) elif command == commands[0x9A]: main_command = gear.QueryPhysicalMinimum(address) self._interface.send(main_command) elif command == commands[0x9B]: main_command = gear.QueryPowerFailure(address) self._interface.send(main_command) elif command == commands[0x9C]: main_command = gear.QueryContentDTR1(address) self._interface.send(main_command) elif command == commands[0x9D]: main_command = gear.QueryContentDTR2(address) self._interface.send(main_command) elif command == commands[0x9E]: main_command = gear.QueryOperatingMode(address) self._interface.send(main_command) elif command == commands[0x9F]: main_command = gear.QueryLightSourceType(address) self._interface.send(main_command) elif command == commands[0xA0]: main_command = gear.QueryActualLevel(address) self._interface.send(main_command) elif command == commands[0xA1]: main_command = gear.QueryMaxLevel(address) self._interface.send(main_command) elif command == commands[0xA2]: main_command = gear.QueryMinLevel(address) self._interface.send(main_command) elif command == commands[0xA3]: main_command = gear.QueryPowerOnLevel(address) self._interface.send(main_command) elif command == commands[0xA4]: main_command = gear.QuerySystemFailureLevel(address) self._interface.send(main_command) elif command == commands[0xA5]: main_command = gear.QueryFadeTimeFadeRate(address) self._interface.send(main_command) elif command == commands[0xA6]: main_command = gear.QueryManufacturerSpecificMode(address) self._interface.send(main_command) elif command == commands[0xA7]: main_command = gear.QueryNextDeviceType(address) self._interface.send(main_command) elif command == commands[0xA8]: main_command = gear.QueryExtendedFadeTime(address) self._interface.send(main_command) elif command == commands[0xAA]: main_command = gear.QueryControlGearFailure(address) self._interface.send(main_command) elif command == commands[0xB0]: main_command = gear.QuerySceneLevel(address, data) self._interface.send(main_command) elif command == commands[0xC0]: main_command = gear.QueryGroupsZeroToSeven(address) self._interface.send(main_command) elif command == commands[0xC1]: main_command = gear.QueryGroupsEightToFifteen(address) self._interface.send(main_command) elif command == commands[0xC2]: main_command = gear.QueryRandomAddressH(address) self._interface.send(main_command) elif command == commands[0xC3]: main_command = gear.QueryRandomAddressM(address) self._interface.send(main_command) elif command == commands[0xC4]: main_command = gear.QueryRandomAddressL(address) self._interface.send(main_command) elif command == commands[0xC5]: self._interface.send(gear.DTR1(data)) self._interface.send(gear.DTR0(data2)) main_command = gear.ReadMemoryLocation(address) self._interface.send(main_command) elif command == commands[0xFF]: main_command = gear.QueryExtendedVersionNumber(address) self._interface.send(main_command) return main_command.is_query