コード例 #1
0
 //static?
 private void StatusDefault(OSAEObject o)
 {
     if (o.Name!=Name)           //Do not change the state of the plugin object!
         switch (o.Type)
         {
             case objTypeHum:
             case objTypeTemp:
             case objTypeTempHum:
                 o.SetState(objStatOff);
                 //sensor s = new sensor();
                 //sensorList.Add(int.Parse(o.Property(propDevId).Value), s);
                 break;
             default:
                 o.SetState(objStatUnKnown);
                 break;
         }
 }
コード例 #2
0
        private int doCommand(OSAEObject o, string addr, OSAEMethod method)
        {
            try
            {
                int deviceId = System.Convert.ToInt32(addr);
                int result = 0;
                if ((o.State.Value.ToUpper() != objStatDisable) || (method.MethodName.ToUpper() == objMtdEnable) ||
                     (o.Name == Name && method.MethodName.ToUpper() == objMtdInit))
                {
                    switch (method.MethodName)
                    {
                        case objMtdBell:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_BELL) > 0)
                            {
                                result = TelldusNETWrapper.tdBell(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.TELLSTICK_BELL);
                            }
                            else
                                logW("doCommand", o.Name, objMtdBell + " Method is not supported on this object.");
                            break;
                        case objMtdDim:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_DIM) > 0)
                            {
                                try
                                {
                                    result = TelldusNETWrapper.tdDim(deviceId, (char)((Int32)(Double.Parse(method.Parameter1) * (255 / 100.0))));
                                }
                                catch (Exception)
                                {
                                    result = TelldusNETWrapper.tdDim(deviceId, '0');
                                }
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdDim + " Method is not supported on this object.");
                            break;
                        case objMtdDown:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_DOWN) > 0)
                            {
                                result = TelldusNETWrapper.tdDown(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdDown + " Method is not supported on this object.");
                            break;
                        case objMtdUp:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_UP) > 0)
                            {
                                result = TelldusNETWrapper.tdUp(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdUp + " Method is not supported on this object.");
                            break;
                        case objMtdStop:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_STOP) > 0)
                            {
                                result = TelldusNETWrapper.tdStop(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdStop + " Method is not supported on this object.");
                            break;
                        case objMtdOn:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_TURNON) > 0)
                            {
                                result = TelldusNETWrapper.tdTurnOn(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdOn + " Method is not supported on this object.");
                            break;
                        case objMtdOff:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_TURNOFF) > 0)
                            {
                                result = TelldusNETWrapper.tdTurnOff(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdOff + " Method is not supported on this object.");
                            break;
                        case objMtdToggle:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_TOGGLE) > 0)
                            {
                                result = TelldusNETWrapper.TELLSTICK_ERROR_METHOD_NOT_SUPPORTED; // !!!!!!!
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdToggle + " Method is not supported on this object.");
                            break;
                        case objMtdExecute:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_EXECUTE) > 0)
                            {
                                result = TelldusNETWrapper.tdExecute(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdExecute + " Method is not supported on this object.");
                            break;
                        case objMtdLearn:
                            if (TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_LEARN) > 0)
                            {
                                result = TelldusNETWrapper.tdLearn(deviceId);
                                logResult(method.MethodName, result, o);
                                setLastProperties(o, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                            }
                            else
                                logW("doCommand", o.Name, objMtdLearn + " Method is not supported on this object.");
                            break;
                        case objMtdRestMaxMin:
                            switch (o.Type)
                            {
                                case objTypeHum:
                                    setPropertyValue(o, propMaxHum, o.Property(propHum).Value);
                                    setPropertyValue(o, propMinHum, o.Property(propHum).Value);
                                    log("doCommand", o.Name, " Reset Min/Max values.");
                                    break;
                                case objTypeTemp:
                                    setPropertyValue(o, propMaxTemp, o.Property(propTemp).Value);
                                    setPropertyValue(o, propMinTemp, o.Property(propTemp).Value);
                                    log("doCommand", o.Name, " Reset Min/Max values.");
                                    break;
                                case objTypeTempHum:
                                    setPropertyValue(o, propMaxHum, o.Property(propHum).Value);
                                    setPropertyValue(o, propMinHum, o.Property(propHum).Value);
                                    setPropertyValue(o, propMaxTemp, o.Property(propTemp).Value);
                                    setPropertyValue(o, propMinTemp, o.Property(propTemp).Value);
                                    log("doCommand", o.Name, " Reset Min/Max values.");
                                    break;
                                default:
                                    logE("doCommand", o.Name, " Reset Min/Max values.", null);
                                    break;
                            }
                            break;

                        case objMtdEnable:
                            switch (o.Type)
                            {
                                case objTypeHum:
                                case objTypeTemp:
                                case objTypeTempHum:
                                    o.SetState(objStatOff);
                                    log("doCommand", o.Name, objStatOff + " Device state set on object.");
                                    break;
                                default:
                                    o.SetState(objStatUnKnown);
                                    log("doCommand", o.Name, objStatUnKnown + " Device state set on object.");
                                    break;
                            }
                            break;
                        case objMtdDis:
                            o.SetState(objStatDisable);  // Should be done automatically on method with same name as state, but not working
                            log("doCommand", o.Name, objStatDisable + " Device state set on object.");
                            break;
                        case objMtdDebugOn:
                            if (debug != true)
                            {
                                debug = true;
                                log("doCommand", o.Name, "Method DebugOn, set debug to TRUE.");
                            }
                            else
                                log("doCommand", o.Name, "Method DebugOn, debug already set to TRUE.");
                            break;
                        case objMtdDebugOff:
                            if (debug != false)
                            {
                                debug = false;
                                log("doCommand", o.Name, "Method DebugOff, set debug to FALSE.");
                            }
                            else
                                log("doCommand", o.Name, "Method DebugOff, debug already set to FALSE.");
                            break;
                        default:
                            logE("doCommand", o.Name, method.MethodName + "Unsuported method: ", null);
                            break;
                        case objMtdRestore:
                            switch (o.Type)
                            {
                                case objTypeBell:
                                    restoreTellstickBellObjectType(Name);
                                    break;
                                case objTypeDim:
                                    restoreTellstickMultiLevelswitchObjectType(Name);
                                    break;
                                case objTypeGroup:
                                    restoreTellstickGroupDeviceObjectType(Name);
                                    break;
                                case objTypeHum:
                                    restoreTellstickHumiditySensorObjectType(Name);
                                    break;
                                case objTypeOnOff:
                                    restoreTellstickBinarySwitchObjectType(Name);
                                    break;
                                case objTypeTemp:
                                    restoreTellstickTemperatureSensorObjectType(Name);
                                    break;
                                case objTypeTempHum:
                                    restoreTellstickTempHumiditySensorObjectType(Name);
                                    break;
                                case objTypeUpDown:
                                    restoreUpDownDeviceObjectType(Name);
                                    break;
                            }
                            break;
                    }
                } // if
                else
                    logW("doCommand", o.Name, objStatDisable + " Methods can not be used when object state is DISABLE!");
                return result;
            }
            catch (Exception ex)
            {
                logE("doCommand", "", "Exception in doCommand: ", ex);
                return -1;
            }
        }
コード例 #3
0
 private void setLastProperties(OSAEObject o, int deviceId, int lastCmd)
 {
     setPropertyValue(o, propLastCmd, MethodToString(lastCmd));
     switch (lastCmd)
     {
         case TelldusNETWrapper.TELLSTICK_TURNON:
             setPropertyValue(o, propLevel, "100");
             o.SetState(objStatOn);
             break;
         case TelldusNETWrapper.TELLSTICK_TURNOFF:
             setPropertyValue(o, propLevel, "0");
             o.SetState(objStatOff);
             break;
         case TelldusNETWrapper.TELLSTICK_DIM:
             try
             {
                 setPropertyValue(o, propLevel, (Decimal.Round((Decimal)(Int32.Parse(TelldusNETWrapper.tdLastSentValue(deviceId)) * (100 / 255.0))).ToString()));
                 if (TelldusNETWrapper.tdLastSentValue(deviceId) != "0")
                     o.SetState(objStatOn);
                 else
                     o.SetState(objStatOff);
             }
             catch (Exception)
             {
                 setPropertyValue(o, propLevel, "");
                 o.SetState(objStatOn);
             }
             break;
         case TelldusNETWrapper.TELLSTICK_TOGGLE:
             if (getPropertyValue(o, propLastCmd) == objEveOn)    // Previous value!
                 o.SetState(objStatOff);
             else
                 o.SetState(objStatOn);
             break;
         case TelldusNETWrapper.TELLSTICK_BELL:
         case TelldusNETWrapper.TELLSTICK_DOWN:
         case TelldusNETWrapper.TELLSTICK_EXECUTE:
         case TelldusNETWrapper.TELLSTICK_STOP:
         case TelldusNETWrapper.TELLSTICK_UP:
             setPropertyValue(o, propLevel, "");
             o.SetState(objStatOn);
             break;
         default:
             o.SetState(objStatUnKnown);
             break;
     }
 }