def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the DALI Light platform.""" from dali.driver.hasseb import SyncHassebDALIUSBDriver from dali.address import Short from dali.command import YesNoResponse, Response import dali.gear.general as gear dali_driver = SyncHassebDALIUSBDriver() import threading lock = threading.RLock() lamps = [] for lamp in range(0,config[CONF_MAX_GEARS]): try: _LOGGER.debug("Searching for Gear on address <{}>".format(lamp)) r = dali_driver.send(gear.QueryControlGearPresent(Short(lamp))) if isinstance(r, YesNoResponse) and r.value: lamps.append(Short(lamp)) except Exception as e: #Not present _LOGGER.error("Error while QueryControlGearPresent: {}".format(e)) break add_devices([DALILight(dali_driver, lock, config[CONF_NAME], l) for l in lamps])
def scan(self): """Scan the bus for devices and ensure there are device objects for each discovered device. """ i = self.get_interface() for sa in range(64): if sa in self._devices: continue response = i.send(gear.QueryControlGearPresent(address.Short(sa))) if response.value: Device(address=sa, bus=self) self._bus_scanned = True
def dali_scan(dali_driver, max_range=4): lamps = [] for lamp in range(0, max_range): try: logging.debug("Search for Lamp {}".format(lamp)) r = dali_driver.send( gear.QueryControlGearPresent(address.Short(lamp))) if isinstance(r, YesNoResponse) and r.value: lamps.append(lamp) except Exception as e: logger.warning("%s not present: %s", lamp, e) return lamps
def dali_scan(driver): """Scan a maximum number of dali devices.""" lamps = [] for lamp in range(0, 63): try: logging.debug("Search for Lamp %s", lamp) present = driver.send(gear.QueryControlGearPresent(address.Short(lamp))) if isinstance(present, YesNoResponse) and present.value: lamps.append(lamp) except DALIError as err: logger.warning("%s not present: %s", lamp, err) return lamps
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the DALI Light platform.""" from dali.address import Short from dali.command import YesNoResponse, Response import dali.gear.general as gear from dali.driver.hasseb import SyncHassebDALIUSBDriverFactory from dali.driver.hasseb import SyncHassebDALIUSBDriver import threading dali_drivers = SyncHassebDALIUSBDriverFactory() for idx, dali_driver in enumerate(dali_drivers): _LOGGER.debug("Found DALI driver") lock = threading.RLock() driver_config = config[CONF_DRIVERS][idx] lamps = [] for lamp in range(0, driver_config[CONF_MAX_GEARS]): try: # @TODO initialize new gears _LOGGER.debug( "Searching for Gear on address <{}>".format(lamp)) r = dali_driver.send(gear.QueryControlGearPresent(Short(lamp))) if isinstance(r, YesNoResponse) and r.value: _LOGGER.debug("Found lamp!") lamps.append(Short(lamp)) except Exception as e: # This will often mean that the driver wasn't found _LOGGER.error( "Error while QueryControlGearPresent: {}".format(e)) _LOGGER.error("Hasseb DALI master not found") break add_devices([ DALILight(dali_driver, lock, driver_config[CONF_NAME], l, idx) for l in lamps ]) add_devices([ DALIBus(dali_driver, lock, driver_config[CONF_NAME], lamps, config[CONF_MAX_BUSES], idx) ])
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