def ProcessMsg(self, _data, instance=1, multiInstanceData = []):
        if _data[0] == SensorMultilevelCmd.SupportedGet:
#            group = self.getGroup(_data[1])
#            if group is not None :
#                msg = Msg("SensorMultilevelCmd_Supported_Report", self.nodeId,  REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER,)
#                msg.Append(TRANSMIT_COMPLETE_OK)
#                msg.Append(self.nodeId)
#                msg.Append(len(group['nodes']) + 5)
#                msg.Append(self.GetCommandClassId)
#                msg.Append(SensorMultilevelCmd.SupportedReport)
#
#                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            self._log.write(LogLevel.Warning, self, "REQUEST SensorMultilevelCmd.SupportedGet Not implemented : {0}".format(GetDataAsHex(_data)))
        elif _data[0] == SensorMultilevelCmd.Get:
            value = self._node.getValue(self.GetCommandClassId, instance, self.getByteIndex(instance))
            if value is not None :
                msg = Msg("SensorMultilevelCmd_Report", self.nodeId,  REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msgData = self.getDataMsg(_data, instance)
                if multiInstanceData :
                    multiInstanceData[2] += len(msgData)
                    for v in multiInstanceData : msg.Append(v)
                else :
                    msg.Append(TRANSMIT_COMPLETE_OK)
                    msg.Append(self.nodeId)
                    msg.Append(len(msgData))
                for v in msgData : msg.Append(v)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        else:
            self._log.write(LogLevel.Warning, self, "CommandClass REQUEST {0}, Not implemented : {1}".format(self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 2
0
 def SendWakeUp(self):
     if self.GetDriver is not None:
         msg = Msg("Send Wakeup Notification", self.nodeId, REQUEST,
                   FUNC_ID_APPLICATION_COMMAND_HANDLER)
         msg.Append(TRANSMIT_COMPLETE_OK)  # 0x00
         msg.Append(self.nodeId)
         msg.Append(0x02)
         msg.Append(self.GetCommandClassId)
         msg.Append(WakeUpCmd.Notification)
         self.GetDriver.SendMsg(msg, MsgQueue.WakeUp)
Esempio n. 3
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        if _data[0] == ConfigurationCmd.Get:
            msg = Msg("ConfigurationCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            param = _data[1]
            value = self._node.getValue(self.GetCommandClassId, instance,
                                        param)
            if value is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                val = value.getValueHex()
                if val is None:
                    self._log.write(
                        LogLevel.Error, self,
                        "Invalid type ({0}) for configuration parameter {1}".
                        format(value.type, param))
                    return
                msg.Append(3 + len(val))
                msg.Append(self.GetCommandClassId)
                msg.Append(ConfigurationCmd.Report)
                msg.Append(param)
                for v in val:
                    msg.Append(v)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 4
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        if _data[0] == PowerlevelCmd.Get:
            msg = Msg("PowerlevelCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msgData = self.getDataMsg(_data, instance)
            if msgData:
                if multiInstanceData:
                    multiInstanceData[2] += len(msgData)
                    for v in multiInstanceData:
                        msg.Append(v)
                else:
                    msg.Append(TRANSMIT_COMPLETE_OK)
                    msg.Append(self.nodeId)
                    msg.Append(len(msgData))
                for v in msgData:
                    msg.Append(v)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 5
0
def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
    print '++++++++++++++++ Clock ProcessMsg +++++++++++++++'
    if _data[0] == ClockCmd.Get:
        msg = Msg("Clock_report", self.nodeId, REQUEST,
                  FUNC_ID_APPLICATION_COMMAND_HANDLER)
        msg.Append(TRANSMIT_COMPLETE_OK)
        msg.Append(self.nodeId)
        msg.Append(4)
        msg.Append(self.GetCommandClassId)
        msg.Append(ClockCmd.Report)
        data = self._node.getValue(self.GetCommandClassId, instance,
                                   ClockIndex.Day).getValueByte() << 5
        data += self._node.getValue(self.GetCommandClassId, instance,
                                    ClockIndex.Hour).getValueByte()
        msg.Append(data)
        msg.Append(
            self._node.getValue(self.GetCommandClassId, instance,
                                ClockIndex.Minute).getValueByte())
        self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

    else:
        self._log.write(
            LogLevel.Warning, self,
            "CommandClass REQUEST {0}, Not implemented : {1}".format(
                self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 6
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
     print '++++++++++++++++ Alarm ProcessMsg +++++++++++++++'
     if _data[0] == ProtectionCmd.Get:
         msg = Msg("ProtectionCmd_Report", self.nodeId, REQUEST,
                   FUNC_ID_APPLICATION_COMMAND_HANDLER)
         value = self._node.getValue(self.GetCommandClassId, instance, 0)
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(3)
         msg.Append(self.GetCommandClassId)
         msg.Append(ProtectionCmd.Report)
         msg.Append(value.getValueByte())
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     else:
         self._log.write(
             LogLevel.Warning, self,
             "CommandClass REQUEST {0}, Not implemented : {1}".format(
                 self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 7
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
     print '++++++++++++++++ Alarm ProcessMsg +++++++++++++++'
     if _data[0] == AlarmCmd.Get:
         msg = Msg("AlarmCmd_Report", self.nodeId, REQUEST,
                   FUNC_ID_APPLICATION_COMMAND_HANDLER)
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(4)
         #            if  len(_data) >= 5 and _data[1] == 0x00 : # Version 2
         data = self.getDataMsg([AlarmCmd.Get, _data[2]], instance)
         msg.Append(len(data))
         for d in data:
             msg.Append(d)
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     else:
         self._log.write(
             LogLevel.Warning, self,
             "CommandClass REQUEST {0}, Not implemented : {1}".format(
                 self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 8
0
 def HandleReportChange(self,
                        msgText,
                        cmdClss,
                        params,
                        instance,
                        queue=MsgQueue.NoOp):
     self._log.write(
         LogLevel.Debug, self,
         "HandleReportChange, {0} - {1} - instance {2}.".format(
             msgText, cmdClss.GetCommandClassName, instance))
     msg = Msg(msgText, self.nodeId, REQUEST,
               FUNC_ID_APPLICATION_COMMAND_HANDLER)
     msgData = cmdClss.getDataMsg(params, instance)
     self._log.write(LogLevel.Debug, self,
                     "Data Value: {0}".format(GetDataAsHex(msgData)))
     if msgData:
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         if instance > 1:  # Multi instance class level
             endPoint = self._node.getEndpointFromInstance(
                 cmdClss.GetCommandClassId, instance)
             self._log.write(
                 LogLevel.Debug, self,
                 "Multi-instance endPoint : {0}".format(endPoint))
             msg.Append(4 + len(msgData))
             multInstclss = self._node.GetCommandClass(0x60)
             msg.Append(multInstclss.GetCommandClassId)
             msg.Append(multInstclss.getCmd)
             msg.Append(endPoint)
             msg.Append(0x00)  # TODO: don't known signification
         else:
             msg.Append(len(msgData))
         print(u"Add msgData {0}".format(msgData))
         for v in msgData:
             msg.Append(v)
         driver = self.GetDriver
         if driver is not None: driver.SendMsg(msg, queue)
         else:
             self._log.write(LogLevel.Warning, self,
                             "Driver not ready, msg not sended.")
     else:
         self._log.write(
             LogLevel.Error, self,
             "No Data find to report it, {0} - {1} - instance {2}.".format(
                 msgText, cmdClss.GetCommandClassName, instance))
Esempio n. 9
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData = []):
        if _data[0] == BatteryCmd.Get:
            msg = Msg("BatteryCmd_Report", self.nodeId,  REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
            value = self._node.getValue(self.GetCommandClassId, instance, 0) # Battery index is allways 0
            if value is not None :
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(3)
                msg.Append(self.GetCommandClassId)
                msg.Append(BatteryCmd.Report)
                msg.Append(value._value)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)    
            else :
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)    

        else:
            self._log.write(LogLevel.Warning, self, "CommandClass REQUEST {0}, Not implemented : {1}".format(self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 10
0
 def Set(self, _route, _queue=MsgQueue.NoOp):
     # Send a No Operation fake message class.
     self._log.write(LogLevel.Detail, self._node,
                     "NoOperation::Set - Routing={0}".format(_route))
     msg = Msg("NoOperation_Set", self.nodeId, REQUEST,
               FUNC_ID_ZW_SEND_DATA)
     msg.Append(self.nodeId)
     msg.Append(2)
     msg.Append(self.GetCommandClassId)
     msg.Append(0)
     if _route:
         msg.Append(self.GetDriver.GetTransmitOptions)
     else:
         msg.Append(TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_NO_ROUTE)
     msg.Append(self.GetDriver.getNextCallbackId())
     self.GetDriver.SendMsg(msg, _queue)
Esempio n. 11
0
 def SendRejectedRequest(self, status):
     """" Status values
     """
     # TODO : Find status values code
     msg = Msg("ApplicationStatusCmd_RejectedRequest", self.nodeId, REQUEST,
               FUNC_ID_APPLICATION_COMMAND_HANDLER)
     msg.Append(TRANSMIT_COMPLETE_OK)
     msg.Append(self.nodeId)
     msg.Append(3 if code != 1 else 4)
     msg.Append(self.GetCommandClassId)
     msg.Append(ApplicationStatusCmd.RejectedRequest)
     msg.Append(status)
     self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
Esempio n. 12
0
 def SendBusyState(self, code):
     """" code values
             0 : Try again later
             1 : Try again in %d seconds
             2 : Request queued, will be executed later
             else : Unknown status
     """
     msg = Msg("ApplicationStatusCmd_Busy", self.nodeId, REQUEST,
               FUNC_ID_APPLICATION_COMMAND_HANDLER)
     msg.Append(TRANSMIT_COMPLETE_OK)
     msg.Append(self.nodeId)
     msg.Append(3 if code != 1 else 4)
     msg.Append(self.GetCommandClassId)
     msg.Append(ApplicationStatusCmd.Busy)
     msg.Append(code)
     if code == 1:  # add extra time (s) data
         msg.Append(10)
     self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
Esempio n. 13
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
     print '++++++++++++++++ SensorBinary ProcessMsg +++++++++++++++'
     if _data[0] == SensorBinaryCmd.Get:
         msg = Msg("SensorBinaryCmd_Report", self.nodeId, REQUEST,
                   FUNC_ID_APPLICATION_COMMAND_HANDLER)
         index = self.getActiveIndex()
         vData = self._node.getValue(self.GetCommandClassId, instance,
                                     index)
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         if self.sensorMaps: msg.Append(3)
         else: msg.Append(2)
         msg.Append(self.GetCommandClassId)
         msg.Append(SensorBinaryCmd.Report)
         msg.Append(vData.getValueByte())
         if self.sensorMaps: msg.Append(self.getByteType(index))
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     else:
         self._log.write(
             LogLevel.Warning, self,
             "CommandClass REQUEST {0}, Not implemented : {1}".format(
                 self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 14
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
     if _data[0] == SwitchBinaryCmd.Get:
         msg = Msg("SwitchBinaryCmd_Report", self.nodeId, REQUEST,
                   FUNC_ID_APPLICATION_COMMAND_HANDLER)
         msgData = self.getDataMsg(_data, instance)
         if msgData:
             if multiInstanceData:
                 multiInstanceData[2] += len(msgData)
                 for v in multiInstanceData:
                     msg.Append(v)
             else:
                 msg.Append(TRANSMIT_COMPLETE_OK)
                 msg.Append(self.nodeId)
                 msg.Append(len(msgData))
             for v in msgData:
                 msg.Append(v)
             self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
         else:
             msg.Append(TRANSMIT_COMPLETE_NOROUTE)
             msg.Append(self.nodeId)
             self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     elif _data[0] == SwitchBinaryCmd.Set:
         value = self._node.getValue(self.GetCommandClassId, instance,
                                     0)  #  index is allways 0
         if value is not None:
             value._value = True if _data[1] else False
             #TODO: Verify is response is necessary ?
             self._log.write(
                 LogLevel.Detail, self,
                 "SwitchBinaryCmd on/off cmd received: {0}".format(
                     'On' if _data[1] else 'Off'))
             self.HandleReportChange("SwitchBinaryCmd_Report", self,
                                     [SwitchBinaryCmd.Get], instance)
     else:
         self._log.write(
             LogLevel.Warning, self,
             "CommandClass REQUEST {0}, Not implemented : {1}".format(
                 self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 15
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        if _data[0] == SwitchAllCmd.Get:
            msg = Msg("SwitchAllCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            value = self._node.getValue(self.GetCommandClassId, instance,
                                        0)  #  index is allways 0
            if value is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(3)
                msg.Append(self.GetCommandClassId)
                msg.Append(SwitchAllCmd.Report)
                msg.Append(value.getValueByte())
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        elif _data[0] in [SwitchAllCmd.On, SwitchAllCmd.Off]:
            #TODO: Call manager to send at all nodes
            self._log.write(
                LogLevel.Warning, self,
                "SwitchALL on/off cmd received, Not impletmented, TODO......")
            msg = Msg("SwitchAllCmd_On-Off_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            value = self._node.getValue(self.GetCommandClassId, instance,
                                        0)  #  index is allways 0
            if value is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(3)
                msg.Append(self.GetCommandClassId)
                msg.Append(SwitchAllCmd.Report)
                msg.Append(value.getValueByte())
                state = value.getValueByte()
                if state == 0:  # Disabled
                    self._log.write(LogLevel.Detail, self._node,
                                    "SwitchALL on/off Disabled")
                elif _data[0] == SwitchAllCmd.Off:
                    if state == 1 or state == 255:  # Off Enabled
                        self._log.write(
                            LogLevel.Detail, self._node,
                            "SwitchALL Off Enabled, TODO: Simulate....")
                    else:
                        self._log.write(LogLevel.Detail, self._node,
                                        "SwitchALL Off Disabled")
                elif _data[0] == SwitchAllCmd.On:
                    if state == 2 or state == 255:  # On Enabled
                        self._log.write(
                            LogLevel.Detail, self._node,
                            "SwitchALL On Enabled, TODO: Simulate....")
                    else:
                        self._log.write(LogLevel.Detail, self._node,
                                        "SwitchALL On Disabled")
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 16
0
    def RequestValue(self, _requestFlags, _getTypeEnum, _instance, _queue):
        """Nothing to do for wakeup"""
        if _instance != 1:
            # This command class doesn't work with multiple instances
            return False
        if _getTypeEnum == WakeUpCmd.IntervalCapabilitiesGet:
            msg = Msg("WakeUpCmd_IntervalCapabilityGet", self.nodeId, REQUEST,
                      FUNC_ID_ZW_SEND_DATA, True,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER,
                      self.GetCommandClassId)
            msg.Append(self.nodeId)
            msg.Append(2)
            msg.Append(self.GetCommandClassId)
            msg.Append(WakeUpCmd.IntervalCapabilitiesGet)
            msg.Append(self.GetDriver.GetTransmitOptions())
            msg.Append(self.GetDriver.getNextCallbackId())
            self.GetDriver.SendMsg(msg, _queue)

        if _getTypeEnum == 0:
            # We won't get a response until the device next wakes up
            msg = Msg("WakeUpCmd_IntervalGet", self.nodeId, REQUEST,
                      FUNC_ID_ZW_SEND_DATA, True,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER,
                      self.GetCommandClassId)
            msg.Append(self.nodeId)
            msg.Append(2)
            msg.Append(self.GetCommandClassId)
            msg.Append(WakeUpCmd.IntervalGet)
            msg.Append(self.GetDriver.GetTransmitOptions)
            msg.Append(self.GetDriver.getNextCallbackId())
            self.GetDriver.SendMsg(msg, _queue)
            return True
        return False
Esempio n. 17
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        print '++++++++++++++++ Meter ProcessMsg +++++++++++++++'
        if not self.meterType: self.setMeterType()
        print 'DATA : ', GetDataAsHex(_data), " -- instance : ", instance
        # Version 1
        if _data[0] == MeterCmd.Get:
            msg = Msg("MeterCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msgData = self.getDataMsg(_data, instance)
            if multiInstanceData:
                multiInstanceData[2] += len(msgData)
                for v in multiInstanceData:
                    msg.Append(v)
            else:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(len(msgData))
            for v in msgData:
                msg.Append(v)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        # Version 2
        elif _data[0] == MeterCmd.SupportedGet:
            msg = Msg("MeterCmd_Supported_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            if multiInstanceData:
                multiInstanceData[2] += 4
                for v in multiInstanceData:
                    msg.Append(v)
            else:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(0x04)
            msg.Append(self.GetCommandClassId)
            msg.Append(MeterCmd.SupportedReport)
            msg.Append(self.getByteType(instance, True))
            if self.m_version > 1: msg.Append(0x05)
            else: msg.Append(0x00)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 18
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        # Version 1  MULTI_INSTANCE
        if _data[0] == MultiInstanceCmd.Get:
            msg = Msg("MultiInstanceCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            clss = self._node.GetCommandClass(_data[1])
            if clss is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(0x04)
                msg.Append(self.GetCommandClassId)
                msg.Append(MultiInstanceCmd.Report)
                msg.Append(clss.GetCommandClassId)
                msg.Append(len(clss.instances))
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                self._log.write(
                    LogLevel.Error, self._node,
                    "MultiInstance Version 1 commandClass 0x%.2x don't exist" %
                    _data[1])

        # Version 2 MULTI_CHANNEL
        elif _data[0] == MultiInstanceCmd.EndPointGet:
            msg = Msg("MultiChannelCmd_EndPoint_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msg.Append(TRANSMIT_COMPLETE_OK)
            msg.Append(self.nodeId)
            msg.Append(0x04)
            msg.Append(self.GetCommandClassId)
            msg.Append(MultiInstanceCmd.EndPointReport)
            endP = 0x80 if self._node.numEndPointsCanChange else 0x00
            if self._node.endPointsAreSameClass: endP = endP or 0x40
            msg.Append(endP)
            msg.Append(self._node.numEndPoints)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        elif _data[0] == MultiInstanceCmd.CapabilityGet:
            endPoint = _data[1]
            msg = Msg("MultiChannelCmd_Capability_Report", self.nodeId,
                      REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msg.Append(TRANSMIT_COMPLETE_OK)
            msg.Append(self.nodeId)
            mapEndpoint = self._node.getEndpointCmdClasses(endPoint)
            cmdClasses = []
            afterMark = []
            for clssId in mapEndpoint:
                clss = self._node.GetCommandClass(clssId)
                if clss.m_afterMark:
                    if not afterMark: afterMark = [0xef]
                    afterMark.append(clssId)
                else:
                    cmdClasses.append(clssId)
            cmdClasses.extend(afterMark)
            msg.Append(5 + len(cmdClasses))
            msg.Append(self.GetCommandClassId)
            msg.Append(MultiInstanceCmd.CapabilityReport)
            # TODO: Handle dynamic devices with msg.Append(endPoint and 0x80), don't known what is dynamic
            msg.Append(endPoint)
            msg.Append(self._node.generic)
            msg.Append(self._node.specific)
            for i in cmdClasses:
                msg.Append(i)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        elif _data[0] == MultiInstanceCmd.EncapV2:
            endPoint = _data[2]
            cmdClss = self._node.GetCommandClass(_data[2])
            if cmdClss is not None:
                msg = Msg("MultiChannelCmd_EncapV2_Report", self.nodeId,
                          REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msgHeader = [TRANSMIT_COMPLETE_OK]
                msgHeader.append(self.nodeId)
                instance = self._node.getInstanceFromEndpoint(
                    _data[3], endPoint)
                if instance:
                    self._log.write(
                        LogLevel.Detail, self._node,
                        "     MultiChannelCmd_EncapV2, Call {0}, instance :{1}"
                        .format(cmdClss.GetCommandClassName, instance))
                    msgHeader.append(4)  # + len(msgData))
                    msgHeader.append(self.GetCommandClassId)
                    msgHeader.append(MultiInstanceCmd.EncapV2)
                    msgHeader.append(endPoint)
                    msgHeader.append(0x01)  # TODO: don't known signification
                    cmdClss.ProcessMsg(_data[4:], instance, msgHeader)
        elif _data[0] == MultiInstanceCmd.Encap:
            endPoint = _data[1]
            cmdClss = self._node.GetCommandClass(_data[2])
            if cmdClss is not None:
                msg = Msg("MultiChannelCmd_Encap_Report", self.nodeId, REQUEST,
                          FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msgHeader = [TRANSMIT_COMPLETE_OK]
                msgHeader.append(self.nodeId)
                instance = self._node.getInstanceFromEndpoint(
                    _data[2], endPoint)
                if instance:
                    self._log.write(
                        LogLevel.Detail, self._node,
                        "     MultiChannelCmd_Encap, Call {0}, instance :{1}".
                        format(cmdClss.GetCommandClassName, instance))
                    msgHeader.append(3)  # + len(msgData))
                    msgHeader.append(instance)
                    msgHeader.append(self.GetCommandClassId)
                    msgHeader.append(MultiInstanceCmd.Encap)
                    cmdClss.ProcessMsg(_data[3:], instance, msgHeader)

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 19
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        if _data[0] == NodeNamingCmd.Get:
            msg = Msg("NodeNamingCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            value = self._node.getValue(self.GetCommandClassId, instance,
                                        0)  # Name index is allways 0
            if value is not None: name = value._value
            else: name = self._node.name
            if name is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                dStr = self.encodeString(
                    name)  # for moment only StringEncoding_ASCII
                msg.Append(2 + len(dStr))
                msg.Append(self.GetCommandClassId)
                msg.Append(NodeNamingCmd.Report)
                for d in dStr:
                    msg.Append(d)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        elif _data[0] == NodeNamingCmd.Set:
            value = self._node.getValue(self.GetCommandClassId, instance,
                                        0)  # Name index is allways 0
            name = self.extractString(_data, len(_data))
            if name:
                if value is not None: value.setVal(name)
                self._node.name = name
                self._log.write(
                    LogLevel.Detail, self, "{0} cmd received: {1}".format(
                        self.getFullNameCmd(_data[0]), name))
                #TODO: Verify is response is necessary ?
#                self.HandleReportChange("NodeNamingCmd_Report", self, [NodeNamingCmd.Get], instance)
            else:
                self._log.write(
                    LogLevel.Warning, self,
                    "{0}, no name extract from data : {1}".format(
                        self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
        elif _data[0] == NodeNamingCmd.LocationGet:
            msg = Msg("NodeNamingCmd_LocationReport", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            value = self._node.getValue(
                self.GetCommandClassId, instance,
                1)  # TODO : Check this : Location index presumed allways 1
            if value is not None: location = value._value
            else: location = self._node.location
            if location is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                dStr = self.encodeString(
                    location)  # for momment only StringEncoding_ASCII
                msg.Append(2 + len(dStr))
                msg.Append(self.GetCommandClassId)
                msg.Append(NodeNamingCmd.LocationReport)
                for d in dStr:
                    msg.Append(d)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOROUTE)
                msg.Append(self.nodeId)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        elif _data[0] == NodeNamingCmd.LocationSet:
            value = self._node.getValue(
                self.GetCommandClassId, instance,
                1)  # TODO : Check this : Location index presumed allways 1
            location = self.extractString(_data, len(_data))
            if location:
                if value is not None: value.setVal(location)
                self._node.location = location
                self._log.write(
                    LogLevel.Detail, self, "{0} cmd received: {1}".format(
                        self.getFullNameCmd(_data[0]), location))
                #TODO: Verify is response is necessary ?
#                self.HandleReportChange("NodeNamingCmd_LocationReport", self, [NodeNamingCmd.LocationGet], instance)
            else:
                self._log.write(
                    LogLevel.Warning, self,
                    "{0}, no location extract from data : {1}".format(
                        self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 20
0
    def ProcessMsg(self, _data, instance=1):
        if _data[0] == ThermostatSetpointCmd.Get:
            setpointName = c_setpointName[_data[1] - self.pointBase]
            value = self._node.getValueByLabel(self.GetCommandClassId,
                                               instance, setpointName)
            print "Thermostat_Setpoint_Report ", setpointName, value
            for v in self._node.getCmdClassValues(self.GetCommandClassId):
                print "     -- ", v.label, v.index
            msg = Msg("Thermostat_Setpoint_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            if value is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                vData = self.EncodeValue(value._value,
                                         1 if value.units == 'C' else 0)
                print "    -- encoding : ", value._value, value.units
                msg.Append(3 + len(vData))
                msg.Append(self.GetCommandClassId)
                msg.Append(ThermostatSetpointCmd.Report)
                msg.Append(value.index)
                for d in vData:
                    msg.Append(d)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg.Append(TRANSMIT_COMPLETE_NOT_IDLE)
                msg.Append(self.nodeId)
                msg.Append(2)
                msg.Append(self.GetCommandClassId)
                msg.Append(ThermostatSetpointCmd.Report)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
                self._log.write(
                    LogLevel.Error, self._node,
                    "Thermostat_Setpoint_Report, value doesn't exist for label {0}."
                    .format(setpointName))

        elif _data[0] == ThermostatSetpointCmd.SupportedGet:
            values = self._node.getCmdClassValues(self.GetCommandClassId)
            msg = Msg("Thermostat_Setpoint_SupportedReport", self.nodeId,
                      REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msg.Append(TRANSMIT_COMPLETE_OK)
            msg.Append(self.nodeId)
            vData = []
            for n in range(0, ThermostatSetpointIndex.Count):
                for value in values:
                    if value.label == c_setpointName[n]:
                        id = (value.index - self.pointBase) / 8
                        if id >= len(vData): vData.append(0)
                        vData[id] |= 1 << ((value.index - self.pointBase) -
                                           (id * 8))
            msg.Append(2 + len(vData))
            msg.Append(self.GetCommandClassId)
            msg.Append(ThermostatSetpointCmd.SupportedReport)
            for d in vData:
                msg.Append(d)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        elif _data[0] == ThermostatSetpointCmd.Set:
            #            _data[1] = index
            vIndex = _data[1] - self.pointBase
            value = self._node.getValue(self.GetCommandClassId, instance,
                                        vIndex)
            if value:
                val = self.ExtractValue(_data[2:],
                                        1 if value.units == 'C' else 0, 0)
                value.setVal(val)
                self._log.write(
                    LogLevel.Info, self._node,
                    "Thermostat Setpoint {0} set to {1}".format(
                        c_setpointName[vIndex], val))
            else:
                self._log.write(
                    LogLevel.Warning, self._node,
                    "Thermostat Setpoint Set unknown value {0} index {1}, value not set to {2}"
                    .format(c_setpointName[vIndex], vIndex, val))

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 21
0
    def ProcessMsg(self, _data, instance=1):
        if _data[0] == AssociationCmd.Get:
            group = self.getGroup(_data[1])
            if group is not None:
                msg = Msg("Association_Report", self.nodeId, REQUEST,
                          FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(len(group['nodes']) + 5)
                msg.Append(self.GetCommandClassId)
                msg.Append(AssociationCmd.Report)
                msg.Append(group['index'])
                msg.Append(group['max_associations'])
                msg.Append(
                    0x00
                )  # TODO: numReportsToFollow , If a device supports a lot of associations, they may come in more than one message. don't known how to do ?
                for n in group['nodes']:
                    msg.Append(n['id'])
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg = Msg("Association_Report", self.nodeId, REQUEST,
                          FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msg.Append(TRANSMIT_COMPLETE_NOT_IDLE)
                msg.Append(self.nodeId)
                msg.Append(2)
                msg.Append(self.GetCommandClassId)
                msg.Append(AssociationCmd.Report)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
                self._log.write(
                    LogLevel.Warning, self._node,
                    "Group index {0} don't exist, Data : {1}".format(
                        _data[1], GetDataAsHex(_data)))
        elif _data[0] == AssociationCmd.GroupingsGet:
            msg = Msg("Association_GroupingsReport", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msg.Append(TRANSMIT_COMPLETE_OK)
            msg.Append(self.nodeId)
            msg.Append(0x03)
            msg.Append(self.GetCommandClassId)
            msg.Append(AssociationCmd.GroupingsReport)
            msg.Append(self.m_numGroups)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        elif _data[0] == AssociationCmd.Set:
            #            _data[1] = group index, _data[2] = nodeId
            if self.addNodeInGroup(_data[1], _data[2]):
                self._log.write(
                    LogLevel.Info, self._node,
                    "Add node {0} to group index {1}".format(
                        _data[2], _data[1]))
            else:
                self._log.write(
                    LogLevel.Info, self._node,
                    "Node {0} allready in group index {1}".format(
                        _data[2], _data[1]))
        elif _data[0] == AssociationCmd.Remove:
            #            _data[1] = group index, _data[2] = nodeId
            if self.removeNodeInGroup(_data[1], _data[2]):
                self._log.write(
                    LogLevel.Info, self._node,
                    "Remove node {0} from group index {1}".format(
                        _data[2], _data[1]))
            else:
                self._log.write(
                    LogLevel.Info, self._node,
                    "Node {0} not in group index {1}".format(
                        _data[2], _data[1]))

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 22
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData = []):
     print '++++++++++++++++ SensorAlarm ProcessMsg +++++++++++++++'
     if _data[0] == SensorAlarmCmd.Get: 
         msg = Msg("SensorAlarmCmd_Report", self.nodeId,  REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
         vData = self._node.getValue(self.GetCommandClassId, instance, 1)
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(5)
         msg.Append(self.GetCommandClassId)
         msg.Append(SensorAlarmCmd.Report)
         msg.Append(self.nodeId)
         msg.Append(self.getTypeAlarm(vData._label))
         msg.Append(vData.getValueByte())
         # TODO: Add extend msg but openzwave don't known what : // uint16 time = (((uint16)_data[4])<<8) | (uint16)_data[5];  Don't know what to do with this yet.
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     elif _data[0] == SensorAlarmCmd.SupportedGet: 
         msg = Msg("SensorAlarmCmd_SupportedReport", self.nodeId,  REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
         values = self._node.getCmdClassValues(self.GetCommandClassId)
         alarms = []
         for v in values : alarms.append(v._label)
         data = self.codeAlarmType(alarms)      
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(2 + len(data))
         msg.Append(self.GetCommandClassId)
         msg.Append(SensorAlarmCmd.SupportedReport)
         for d in data : 
             msg.Append(d)
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     else:
         self._log.write(LogLevel.Warning, self, "CommandClass REQUEST {0}, Not implemented : {1}".format(self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 23
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
     print '++++++++++++++++ WakeUp ProcessMsg +++++++++++++++'
     if _data[0] == WakeUpCmd.IntervalGet:
         msg = Msg("WakeUpCmd_IntervalReport", self.nodeId, REQUEST,
                   FUNC_ID_APPLICATION_COMMAND_HANDLER)
         vInterval = self._node.getValue(self.GetCommandClassId, instance,
                                         0)
         msgData = vInterval.getValueHex(24)
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(6)
         msg.Append(self.GetCommandClassId)
         msg.Append(WakeUpCmd.IntervalReport)
         for v in msgData[1:]:
             msg.Append(v)
         msg.Append(self.GetDriver.nodeId)
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     elif _data[0] == WakeUpCmd.NoMoreInformation:
         self._log.write(
             LogLevel.Detail, self,
             "WakeUpCmd.NoMoreInformation received, go to sleep for {0}s.".
             format(self.timeoutWakeUp))
         self._lastTime = time.time()
         self.m_awake = False
     elif _data[0] == WakeUpCmd.IntervalCapabilitiesGet:
         msg = Msg("WakeUpCmd_IntervalCapabilitiesReport", self.nodeId,
                   REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
         msgData = []
         for i in range(1, 5):  # get value for capabilities index 1 to 4
             value = self._node.getValue(self.GetCommandClassId, instance,
                                         i)
             msgData.extend(value.getValueHex(24)[1:])
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(2 + len(msgData))
         msg.Append(self.GetCommandClassId)
         msg.Append(WakeUpCmd.IntervalCapabilitiesReport)
         for v in msgData:
             msg.Append(v)
         msg.Append(self.GetDriver.nodeId)
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     else:
         self._log.write(
             LogLevel.Warning, self,
             "CommandClass REQUEST {0}, Not implemented : {1}".format(
                 self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
 def ProcessMsg(self, _data, instance=1):
     msg = Msg("ManufacturerSpecificCmd_Report", self.nodeId, REQUEST,
               FUNC_ID_APPLICATION_COMMAND_HANDLER)
     if _data[0] == ManufacturerSpecificCmd.Get:
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         msg.Append(0x08)
         msg.Append(self.GetCommandClassId)
         msg.Append(ManufacturerSpecificCmd.Report)
         # first two bytes are manufacturer id code
         manufacturerId = int(self._node.GetManufacturerId, 16)
         msg.Append((manufacturerId & 0x0000ff00) >> 8)
         msg.Append((manufacturerId & 0x000000ff))
         # next four are product type and product id
         productType = int(self._node.GetProductType, 16)
         msg.Append((productType & 0x0000ff00) >> 8)
         msg.Append((productType & 0x000000ff))
         productId = int(self._node.GetProductId, 16)
         msg.Append((productId & 0x0000ff00) >> 8)
         msg.Append((productId & 0x000000ff))
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
Esempio n. 25
0
    def ProcessMsg(self, _data, instance=1):
        if _data[0] == VersionCmd.Get:
            msg = Msg("VersionCmd_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msg.Append(TRANSMIT_COMPLETE_OK)
            msg.Append(self.nodeId)
            msg.Append(0x07)
            msg.Append(self.GetCommandClassId)
            msg.Append(VersionCmd.Report)
            libraryValue = self._node.getValue(self.GetCommandClassId,
                                               instance, VersionIndex.Library)
            if libraryValue is None:
                self._log.write(
                    LogLevel.Error, self,
                    "CommandClass Version as no Library form xml file.")
                return
            msg.Append(int(libraryValue.getVal()))
            protocolValue = self._node.getValue(self.GetCommandClassId,
                                                instance,
                                                VersionIndex.Protocol)
            if protocolValue is None:
                self._log.write(
                    LogLevel.Error, self,
                    "CommandClass Version as no Protocol form xml file.")
                return
            p = protocolValue.getVal().split('.')
            msg.Append(int(p[0]))
            msg.Append(int(p[1]))
            applicationValue = self._node.getValue(self.GetCommandClassId,
                                                   instance,
                                                   VersionIndex.Application)
            if applicationValue is None:
                self._log.write(
                    LogLevel.Error, self,
                    "CommandClass Version as no Application form xml file.")
                return
            p = applicationValue.getVal().split('.')
            msg.Append(int(p[0]))
            msg.Append(int(p[1]))
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
        elif _data[0] == VersionCmd.CommandClassGet:
            msg = Msg("VersionCmd_CommandClass_Report", self.nodeId, REQUEST,
                      FUNC_ID_APPLICATION_COMMAND_HANDLER)
            clssId = _data[1]
            clss = self._node.GetCommandClass(_data[1])
            if clss is not None:
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                msg.Append(0x04)
                msg.Append(self.GetCommandClassId)
                msg.Append(VersionCmd.CommandClassReport)
                msg.Append(clss.GetCommandClassId)
                msg.Append(clss.m_version)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                self._log.write(
                    LogLevel.Warning, self,
                    "Bad commandClass id version request :0x%0x%.2x" %
                    _data[1])

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 26
0
    def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
        print '++++++++++++++++ Multi Instance Association ProcessMsg +++++++++++++++'
        if _data[0] == MultiInstanceAssociationCmd.Get:
            cAss = self._node.GetCommandClass(
                0x85)  # COMMAND_CLASS_ASSOCIATION
            group = cAss.getGroup(_data[1])  # _data[1] group index
            if group is not None:
                msg = Msg("Multi_Instance_Association_report", self.nodeId,
                          REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msg.Append(TRANSMIT_COMPLETE_OK)
                msg.Append(self.nodeId)
                size = 0
                nodes = []
                nodes_i = []
                for n in group['nodes']:
                    if n['instance'] == 0x00:
                        nodes.append(n)
                        size += 1
                    else:
                        nodes_i.append(n)
                        size += 2
                if nodes_i: size += 1  # add multi-instance marker place
                msg.Append(size + 5)
                msg.Append(self.GetCommandClassId)
                msg.Append(MultiInstanceAssociationCmd.Report)
                #            data = self._node.getValue(self.GetCommandClassId, instance, _data[1]).getValueByte() #_data[1] groupe index
                msg.Append(group['index'])
                msg.Append(group['max_associations'])
                msg.Append(
                    0
                )  # TODO: numReportsToFollow , If a device supports a lot of associations, they may come in more than one message.
                for n in nodes:
                    msg.Append(n['id'])
                if nodes_i:
                    msg.Append(0x00)  # multi-instance marker
                    for n in nodes_i:
                        msg.Append(n['id'])
                        msg.Append(n['instance'])
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
            else:
                msg = Msg("Multi_Instance_Association_Report", self.nodeId,
                          REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
                msg.Append(TRANSMIT_COMPLETE_NOT_IDLE)
                msg.Append(self.nodeId)
                msg.Append(2)
                msg.Append(self.GetCommandClassId)
                msg.Append(MultiInstanceAssociationCmd.Report)
                self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
                self._log.write(
                    LogLevel.Warning, self._node,
                    "Group index {0} don't exist, Data : {1}".format(
                        _data[1], GetDataAsHex(_data)))
        elif _data[0] == MultiInstanceAssociationCmd.GroupingsGet:
            cAss = self._node.GetCommandClass(
                0x85)  # COMMAND_CLASS_ASSOCIATION
            msg = Msg("Multi_Instance_Association_Report", self.nodeId,
                      REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
            msg.Append(TRANSMIT_COMPLETE_OK)
            msg.Append(self.nodeId)
            msg.Append(0x03)
            msg.Append(self.GetCommandClassId)
            msg.Append(MultiInstanceAssociationCmd.GroupingsReport)
            msg.Append(cAss.m_numGroups)
            self.GetDriver.SendMsg(msg, MsgQueue.NoOp)

        elif _data[0] == MultiInstanceAssociationCmd.Set:
            #            _data[1] = group index
            cAss = self._node.GetCommandClass(
                0x85)  # COMMAND_CLASS_ASSOCIATION
            if _data[
                    2] == 0x00:  # marker 0x00 for instance _data[3] = nodeId, _data[4] = instance
                if cAss.addNodeInGroup(_data[1], _data[3], _data[4]):
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Add node {0} multi-instance {1} to group index {2}".
                        format(_data[3], _data[4], _data[1]))
                else:
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Node {0} multi-instance {1} allready in group index {2}"
                        .format(_data[2], _data[4], _data[1]))
            else:  #" _data[2] = nodeId
                if cAss.addNodeInGroup(_data[1], _data[2]):
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Add node {0} to group index {1}".format(
                            _data[2], _data[1]))
                else:
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Node {0} allready in group index {1}".format(
                            _data[2], _data[1]))
        elif _data[0] == MultiInstanceAssociationCmd.Remove:
            #            _data[1] = group index
            cAss = self._node.GetCommandClass(
                0x85)  # COMMAND_CLASS_ASSOCIATION
            if _data[
                    2] == 0x00:  # marker 0x00 for instance _data[3] = nodeId, _data[4] = instance
                if cAss.removeNodeInGroup(_data[1], _data[3], _data[4]):
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Remove node {0} multi-instance {1} from group index {2}"
                        .format(_data[3], _data[4], _data[1]))
                else:
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Node {0} multi-instance {1} not in group index {2}".
                        format(_data[2], _data[4], _data[1]))
            else:  #" _data[2] = nodeId
                if cAss.removeNodeInGroup(_data[1], _data[2]):
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Remove node {0} from group index {1}".format(
                            _data[2], _data[1]))
                else:
                    self._log.write(
                        LogLevel.Info, self._node,
                        "Node {0} not in group index {1}".format(
                            _data[2], _data[1]))

        else:
            self._log.write(
                LogLevel.Warning, self,
                "CommandClass REQUEST {0}, Not implemented : {1}".format(
                    self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))
Esempio n. 27
0
 def ProcessMsg(self, _data, instance=1, multiInstanceData=[]):
     if _data[0] == SwitchMultilevelCmd.Get:
         value = self._node.getValue(self.GetCommandClassId, instance,
                                     self.getByteIndex(instance))
         if value is not None:
             msg = Msg("SwitchMultilevelCmd_Report", self.nodeId, REQUEST,
                       FUNC_ID_APPLICATION_COMMAND_HANDLER)
             msgData = self.getDataMsg(_data, instance)
             if multiInstanceData:
                 multiInstanceData[2] += len(msgData)
                 for v in multiInstanceData:
                     msg.Append(v)
             else:
                 msg.Append(TRANSMIT_COMPLETE_OK)
                 msg.Append(self.nodeId)
                 msg.Append(len(msgData))
             for v in msgData:
                 msg.Append(v)
             self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     elif _data[0] == SwitchMultilevelCmd.SupportedGet:
         msg = Msg("SwitchMultilevelCmd_SupportedReport", self.nodeId,
                   REQUEST, FUNC_ID_APPLICATION_COMMAND_HANDLER)
         msg.Append(TRANSMIT_COMPLETE_OK)
         msg.Append(self.nodeId)
         switchtype1label = 0
         try:
             switchtype1label = self.extraParams[instance]['switchtype1']
         except:
             raise CommandClassException(
                 "Get switchtype1label Fail, Index not found for label : {0}."
                 .format(self.extraParams[instance]), self)
         switchtype2label = 0
         try:
             switchtype2label = self.extraParams[instance]['switchtype2']
         except:
             raise CommandClassException(
                 "Get switchtype2label Fail, Index not found for label : {0}."
                 .format(self.extraParams[instance]), self)
         msg.Append(4)
         msg.Append(self.GetCommandClassId)
         msg.Append(SwitchMultilevelCmd.SupportedReport)
         msg.Append(switchtype1label & 0x1f)
         msg.Append(switchtype2label & 0x1f)
         self.GetDriver.SendMsg(msg, MsgQueue.NoOp)
     elif _data[0] == SwitchMultilevelCmd.StartLevelChange:
         direction = _data[1] & 0xdF
         startLevel = _data[2]
         ignoreStartLevel = True if (_data[1] & 0x20) else False
         self._log.write(
             LogLevel.Debug, self,
             "CommandClass REQUEST {0}, direction : {1}, startLevel : {2}, ignoreStartLevel : {3}"
             .format(self.getFullNameCmd(_data[0]), direction, startLevel,
                     ignoreStartLevel))
         value = self._node.getValue(self.GetCommandClassId, instance,
                                     SwitchMultilevelIndex.IgnoreStartLevel)
         if value is not None: value.setVal(ignoreStartLevel)
         value = self._node.getValue(self.GetCommandClassId, instance,
                                     SwitchMultilevelIndex.StartLevel)
         if value is not None: value.setVal(startLevel)
         if self.m_version >= 2:
             value = self._node.getValue(self.GetCommandClassId, instance,
                                         SwitchMultilevelIndex.Duration)
             if value is not None: value.setVal(_data[3])
             if self.m_version >= 3:
                 value = self._node.getValue(self.GetCommandClassId,
                                             instance,
                                             SwitchMultilevelIndex.Step)
                 if value is not None: value.setVal(_data[4])
         threading.Thread(
             None, self._handleChangeLevel,
             "th_Handle_ChangeLevel_class_0x%0.2x." %
             self.GetCommandClassId, (direction), {
                 'instance': instance
             }).start()
     elif _data[0] == SwitchMultilevelCmd.StopLevelChange:
         self.runChange = False
     elif _data[0] == SwitchMultilevelCmd.Get:
         value = self._node.getValue(self.GetCommandClassId, instance,
                                     self.getByteIndex(instance))
         if value is not None: value.setVal(_data[1])
     else:
         self._log.write(
             LogLevel.Warning, self,
             "CommandClass REQUEST {0}, Not implemented : {1}".format(
                 self.getFullNameCmd(_data[0]), GetDataAsHex(_data)))