diff --git a/README.rst b/README.rst index 250292b..f35ad1f 100644 --- a/README.rst +++ b/README.rst @@ -35,38 +35,53 @@ Library structure - ``dali`` - ``address`` - Device addressing - - ``bus`` - DALI bus object + + - ``bus`` - DALI bus and attached devices + - ``command`` - Command registry, interface to command decoding + - ``compat`` - Compatibility code for Python 2 and 3 - - ``device`` - Control devices and events from them + + - ``device`` - DALI control devices as defined in IEC 62386 - ``general`` - Commands and events from part 103 - ``driver`` - Objects to communicate with physical DALI gateways or services - ``base`` - General driver contracts + - ``hasseb`` - Driver for Hasseb DALI Master (needs to be adopted to dali.driver.base API) + - ``tridonic`` - Driver for Tridonic DALI USB + - ``daliserver`` - Driver for https://github.com/onitake/daliserver (needs to be adopted to dali.driver.base API) - ``exceptions`` - DALI related exceptions + - ``frame`` - Forward and backward frames - - ``gear`` - Control gear + + - ``gear`` - DALI control gear as defined in IEC 62386 - ``emergency`` - Commands from part 202 + - ``general`` - Commands from part 102 + - ``incandescent`` - Commands from part 205 - - ``fluorescent`` - Commands from part 201 (not yet implemented) + - ``led`` - Commands from part 207 Contributors ------------ -- Stephen Early (Autor) +- Stephen Early (Author) + - Robert Niederreiter + - Diogo Gomes + - Caiwan + - Boldie diff --git a/dali/bus.py b/dali/bus.py index 3b62ce6..21d831e 100644 --- a/dali/bus.py +++ b/dali/bus.py @@ -1,6 +1,7 @@ from __future__ import division +from __future__ import unicode_literals from dali import address -from dali import device +from dali.address import Short from dali.exceptions import BadDevice from dali.exceptions import DeviceAlreadyBound from dali.exceptions import DuplicateDevice @@ -12,6 +13,23 @@ import time +class Device(object): + """Any DALI slave device that has been configured with a short address.""" + + def __init__(self, address, name=None, bus=None): + if not isinstance(address, int) or address < 0 or address > 63: + raise ValueError("address must be an integer in the range 0..63") + self.address = address + self._addressobj = Short(address) + self.bus = None + if bus: + self.bind(bus) + + def bind(self, bus): + """Bind this device object to a particular DALI bus.""" + bus.add_device(self) + + class Bus(object): """A DALI bus.""" @@ -55,7 +73,7 @@ def scan(self): response = i.send( gear.QueryControlGearPresent(address.Short(sa))) if response.value: - device.Device(address=sa, bus=self) + Device(address=sa, bus=self) self._bus_scanned = True def set_search_addr(self, addr): @@ -114,7 +132,7 @@ def assign_short_addresses(self): if r.value is not True: raise ProgramShortAddressFailure(new_addr) i.send(gear.Withdraw()) - device.Device(address=new_addr, bus=self) + Device(address=new_addr, bus=self) else: i.send(gear.Terminate()) raise NoFreeAddress() diff --git a/dali/command.py b/dali/command.py index 6a49479..12d02a5 100644 --- a/dali/command.py +++ b/dali/command.py @@ -232,7 +232,7 @@ def response(self): def _check_destination(destination): """Check that a valid destination has been specified. - destination can be a dali.device.Device object with + destination can be a dali.bus.Device object with _addressobj attribute, a dali.address.Address object with add_to_frame method, or an integer which will be wrapped in a dali.address.Address object. @@ -243,7 +243,7 @@ def _check_destination(destination): destination = address.Short(destination) if hasattr(destination, "add_to_frame"): return destination - raise ValueError("destination must be an integer, dali.device.Device " + raise ValueError("destination must be an integer, dali.bus.Device " "object or dali.address.Address object") def __str__(self): diff --git a/dali/device.py b/dali/device.py deleted file mode 100644 index 8d8e3a1..0000000 --- a/dali/device.py +++ /dev/null @@ -1,25 +0,0 @@ -from dali.address import Short - - -############################################################################### -# XXX: There exists a package names device. so this module is a relict??? -############################################################################### - - -class Device(object): - """Any DALI slave device that has been configured with a short - address. - """ - - def __init__(self, address, name=None, bus=None): - if not isinstance(address, int) or address < 0 or address > 63: - raise ValueError("address must be an integer in the range 0..63") - self.address = address - self._addressobj = Short(address) - self.bus = None - if bus: - self.bind(bus) - - def bind(self, bus): - """Bind this device object to a particular DALI bus.""" - bus.add_device(self)