Exemple #1
0
 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)
Exemple #2
0
def on_message_cmd(mosq, dalic, msg):
    logger.debug("Command on %s: %s", msg.topic, msg.payload)
    light = int(
        re.search(MQTT_COMMAND_TOPIC.format(MQTT_BASE_TOPIC, '(.+?)'),
                  msg.topic).group(1))
    if msg.payload == MQTT_PAYLOAD_OFF:
        try:
            logger.debug("Set light <%s> to %s", light, msg.payload)
            dalic.send(gear.Off(address.Short(light)))
            mosq.publish(MQTT_STATE_TOPIC.format(MQTT_BASE_TOPIC, light),
                         MQTT_PAYLOAD_OFF,
                         retain=True)
        except:
            logger.error("Failed to set light <%s> to %s", light, "OFF")
def on_message_brightness_cmd(mqtt_client, data_object, msg):
    """Callback on MQTT brightness command message."""
    logger.debug("Brightness Command on %s: %s", msg.topic, msg.payload)
    light = re.search(
        MQTT_BRIGHTNESS_COMMAND_TOPIC.format(data_object["base_topic"],
                                             "(.+?)"),
        msg.topic,
    ).group(1)
    try:
        if light not in data_object["all_lamps"]:
            raise KeyError
        lamp_object = data_object["all_lamps"][light]
        level = None
        try:
            level = msg.payload.decode("utf-8")
            level = int(level)
            lamp_object.level = level
            if lamp_object.level == 0:
                # 0 in DALI is turn off with fade out
                mqtt_client.publish(
                    MQTT_STATE_TOPIC.format(data_object["base_topic"], light),
                    MQTT_PAYLOAD_OFF,
                    retain=True,
                )
                data_object["driver"].send(
                    gear.Off(lamp_object.short_address.address))
                logger.debug("Set light <%s> to OFF", light)

            else:
                mqtt_client.publish(
                    MQTT_STATE_TOPIC.format(data_object["base_topic"], light),
                    MQTT_PAYLOAD_ON,
                    retain=True,
                )
            mqtt_client.publish(
                MQTT_BRIGHTNESS_STATE_TOPIC.format(data_object["base_topic"],
                                                   light),
                lamp_object.level,
                retain=True,
            )
        except ValueError as err:
            logger.error(
                "Can't convert <%s> to integer %d..%d: %s",
                str(level),
                lamp_object.min_level,
                lamp_object.max_level,
                err,
            )
    except KeyError:
        logger.error("Lamp %s doesn't exists", light)
Exemple #4
0
def on_message_cmd(mqtt_client, data_object, msg):
    """Callback on MQTT command message."""
    logger.debug("Command on %s: %s", msg.topic, msg.payload)
    light = re.search(
        MQTT_COMMAND_TOPIC.format(data_object["base_topic"], "(.+?)"), msg.topic
    ).group(1)
    if msg.payload == MQTT_PAYLOAD_OFF:
        try:
            lamp_object = data_object["all_lamps"][light]
            logger.debug("Set light <%s> to %s", light, msg.payload)
            data_object["driver"].send(gear.Off(lamp_object.short_address))
            mqtt_client.publish(
                MQTT_STATE_TOPIC.format(data_object["base_topic"], light),
                MQTT_PAYLOAD_OFF,
                retain=True,
            )
        except DALIError as err:
            logger.error("Failed to set light <%s> to %s: %s", light, "OFF", err)
        except KeyError:
            logger.error("Lamp %s doesn't exists", light)
Exemple #5
0
 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