Exemplo n.º 1
0
        public static bool WakeUp(ILogger logger, string macAddress, IDriverContext ctx)
        {
            if (ctx.IsTest)
            {
                return(true);
            }
            var retVal = false;

            var packet = BuildWakeUpPacket(macAddress);

            if (packet.Length > 0)
            {
                // WOL packet is sent over UDP 255.255.255.0:40000.
                using (UdpClient client = new UdpClient())
                {
                    client.Client.Connect(IPAddress.Broadcast, 40000);
                    client.EnableBroadcast = true;
                    // Submit
                    int result = client.Client.Send(packet);
                    logger.LogHexOut(packet);
                    if (result > 0)
                    {
                        retVal = true;
                    }
                }
            }

            return(retVal);
        }
 public BitcoinValueNode(IDriverContext driverContext, string currency, bool addSymbol,
                         BitcoinNode bitcoinNode) : base(driverContext)
 {
     _currency    = currency;
     _addSymbol   = addSymbol;
     _bitcoinNode = bitcoinNode;
 }
Exemplo n.º 3
0
 public StoreApp(IDriverContext context, Capabilities capabilities, IUtils utils)
 {
     // TODO verify capabilities
     this.context = context;
     this.capabilities = capabilities;
     this.utils = utils;
 }
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            IkeaTradfriDevice tradfriDevice = null;

            if (ctx.NodeInstance.This2NodeTemplate == IkeaTradfriFactory.RelayGuid)
            {
                tradfriDevice = new IkeaTradfriRelayNode(ctx, this, TradfriDeviceType.SwitchPlug);
            }
            else if (ctx.NodeInstance.This2NodeTemplate == IkeaTradfriFactory.LightGuid)
            {
                tradfriDevice = new IkeaTradfriLightNode(ctx, this);
            }
            else if (ctx.NodeInstance.This2NodeTemplate == IkeaTradfriFactory.LightColorGuid)
            {
                tradfriDevice = new IkeaTradfriLightColorNode(ctx, this);
            }
            else if (ctx.NodeInstance.This2NodeTemplate == IkeaTradfriFactory.LightDimmerGuid)
            {
                tradfriDevice = new IkeaTradfriLightDimmerNode(ctx, this);
            }

            if (tradfriDevice != null)
            {
                Gateway.Devices.Add(tradfriDevice);
                return(tradfriDevice);
            }
            return(null);
        }
Exemplo n.º 5
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var m = new KnxMiddleGroup(ctx, Driver);

            AddChild(m);
            return(m);
        }
Exemplo n.º 6
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            if (ctx.NodeInstance.This2NodeTemplateNavigation.ObjId == SunDriverFactory.SunSetGuid)
            {
                return(new SunDriverNode(ctx, (a, b) => a.Sunset));
            }
            if (ctx.NodeInstance.This2NodeTemplateNavigation.ObjId == SunDriverFactory.SunRiseGuid)
            {
                return(new SunDriverNode(ctx, (a, b) => a.Sunrise));
            }
            if (ctx.NodeInstance.This2NodeTemplateNavigation.ObjId == SunDriverFactory.SunDusk)
            {
                return(new SunDriverNode(ctx, (a, b) => a.Sunset.AddMinutes(30) > b && b < a.Sunrise.AddMinutes(30)));
            }

            if (ctx.NodeInstance.This2NodeTemplateNavigation.ObjId == SunDriverFactory.SunDawn)
            {
                return(new SunDriverNode(ctx, (a, b) => a.Sunrise.AddMinutes(30) > b && b < a.Sunset.AddMinutes(30)));
            }
            if (ctx.NodeInstance.This2NodeTemplateNavigation.ObjId == SunDriverFactory.SunIsRiseGuid)
            {
                return(new SunDriverNode(ctx, (a, b) => {
                    return b > a.Sunrise && b < a.Sunset;
                }));
            }
            if (ctx.NodeInstance.This2NodeTemplateNavigation.ObjId == SunDriverFactory.SunIsSetGuid)
            {
                return(new SunDriverNode(ctx, (a, b) =>
                {
                    return b < a.Sunset && b < a.Sunrise;
                }));
            }

            return(null);
        }
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            BitcoinValueNode node = null;

            switch (ctx.NodeInstance.This2NodeTemplateNavigation.Key)
            {
            case "blockchain-btc-usd":
                node = new BitcoinValueNode(ctx, "USD", false, this);
                break;

            case "blockchain-btc-eur":
                node = new BitcoinValueNode(ctx, "EUR", false, this);
                break;

            case "blockchain-btc-usd-with-symbol":
                node = new BitcoinValueNode(ctx, "USD", true, this);
                break;

            case "blockchain-btc-eur-with-symbol":
                node = new BitcoinValueNode(ctx, "EUR", true, this);
                break;
            }

            AddNode(node);

            return(node);
        }
Exemplo n.º 8
0
 public StoreApp(IDriverContext context, Capabilities capabilities, IUtils utils)
 {
     // TODO verify capabilities
     this.context      = context;
     this.capabilities = capabilities;
     this.utils        = utils;
 }
Exemplo n.º 9
0
        private void Initialize(string browserName, string environment)
        {
            LocalRemoteFactory factory = new LocalRemoteFactory();

            this.gateway = factory.DriverGateway(environment);
            driver       = this.gateway.GetDriver(browserName, driver);
        }
Exemplo n.º 10
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var att = new KnxDpt2ValueAttribute(ctx, this, ctx.NodeInstance.This2NodeTemplateNavigation.Key == "knx-dpt2-value" ? 0 : 1);

            _children.Add(att);
            return(att);
        }
 public NewSessionHandler(IDriverContext context, SessionManager sessionManager, IUACPomptHandler uacHandler, IUtils utils)
 {
     this.context = context;
     this.sessionManager = sessionManager;
     this.uacHandler = uacHandler;
     this.utils = utils;
 }
Exemplo n.º 12
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var m = new KnxMainGroup(ctx, _driver);

            _mainGroups.Add(m);
            return(m);
        }
Exemplo n.º 13
0
 public DesktopApp(IDriverContext context, Capabilities capabilities, IUACPomptHandler uacHandler, IUtils utils)
 {
     this.context      = context;
     this.capabilities = capabilities; // TODO validate capabilities
     this.uacHandler   = uacHandler;
     this.utils        = utils;
 }
Exemplo n.º 14
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            switch (ctx.NodeInstance.This2NodeTemplateNavigation.Key)
            {
            case "mbus-oms-datetime":
                return(new OmsDriverAttribute(ctx, 0));

            case "mbus-oms-a+":
                return(new OmsDriverAttribute(ctx, 1));

            case "mbus-oms-a-":
                return(new OmsDriverAttribute(ctx, 2));

            case "mbus-oms-r+":
                return(new OmsDriverAttribute(ctx, 3));

            case "mbus-oms-r-":
                return(new OmsDriverAttribute(ctx, 4));

            case "mbus-oms-power+":
                return(new OmsDriverAttribute(ctx, 5));

            case "mbus-oms-power-":
                return(new OmsDriverAttribute(ctx, 6));

            case "mbus-oms-reactive-power+":
                return(new OmsDriverAttribute(ctx, 7));

            case "mbus-oms-reactive-power-":
                return(new OmsDriverAttribute(ctx, 8));
            }

            throw new NotImplementedException();
        }
Exemplo n.º 15
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var dev = new ModBusSlaveDevice(ctx, _modBusDriver);

            _childs.Add(dev);
            return(dev);
        }
Exemplo n.º 16
0
 public NewSessionHandler(IDriverContext context, SessionManager sessionManager, IUACPomptHandler uacHandler, IUtils utils)
 {
     this.context        = context;
     this.sessionManager = sessionManager;
     this.uacHandler     = uacHandler;
     this.utils          = utils;
 }
Exemplo n.º 17
0
        public HomeKitDriver(IDriverContext driverContext) : base(driverContext)
        {
            var highestAid = 1;

            foreach (var child in driverContext.NodeInstance.InverseThis2ParentNodeInstanceNavigation)
            {
                if (child.This2NodeTemplateNavigation.Key == "pairing-key")
                {
                    continue;
                }

                var aidProperty = child.GetProperty(HomeKitFactory.AidPropertyKey);

                if (!aidProperty.ValueDouble.HasValue)
                {
                    continue;
                }

                highestAid = Math.Max(highestAid, Convert.ToInt32(aidProperty.ValueDouble.Value));
            }

            _aidGenerator = new AccessoryInstanceIdGenerator(highestAid);

            driverContext.Logger.LogDebug($"Highest generated AID is {highestAid}");

            InitializeAidProperties(driverContext);
        }
Exemplo n.º 18
0
 public DesktopApp(IDriverContext context, Capabilities capabilities, IUACPomptHandler uacHandler, IUtils utils)
 {
     this.context = context;
     this.capabilities = capabilities; // TODO validate capabilities
     this.uacHandler = uacHandler;
     this.utils = utils;
 }
Exemplo n.º 19
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var att = new Attribute(ctx);

            _attributes.Add(att);

            return(att);
        }
Exemplo n.º 20
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var node = new AutomaticaRemoteNode(ctx, _driver);

            _driver.AddRemoteNode(node, ctx.NodeInstance.ObjId);

            return(node);
        }
Exemplo n.º 21
0
 public override IDriverNode CreateDriverNode(IDriverContext ctx)
 {
     if (ctx.NodeInstance.This2NodeTemplate == HueBridgeSimulatorDriverFactory.OnOffLight)
     {
         return(new HueOnOffNode(ctx, this));
     }
     return(null);
 }
Exemplo n.º 22
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var node = new AutomaticaRemoteNode(ctx, this);

            _nodeMap.Add(ctx.NodeInstance.ObjId, node);

            return(node);
        }
Exemplo n.º 23
0
        internal static KnxLevelBase CreateDriverNode(string key, IDriverContext ctx, IKnxDriver driver)
        {
            KnxLevelBase attribute = null;

            switch (key)
            {
            case "knx-dpt1":
                attribute = new KnxDpt1Attribute(ctx, driver);
                break;

            case "knx-dpt2":
                attribute = new KnxDpt2Attribute(ctx, driver);
                break;

            case "knx-dpt3":
                attribute = new KnxDpt3Attribute(ctx, driver);
                break;

            case "knx-dpt4":
                attribute = new KnxDpt4Attribute(ctx, driver);
                break;

            case "knx-dpt5":
                attribute = new KnxDpt5Attribute(ctx, driver);
                break;

            case "knx-dpt6":
                attribute = new KnxDpt6Attribute(ctx, driver);
                break;

            case "knx-dpt7":
                attribute = new KnxDpt7Attribute(ctx, driver);
                break;

            case "knx-dpt8":
                attribute = new KnxDpt8Attribute(ctx, driver);
                break;

            case "knx-dpt9":
                attribute = new KnxDpt9Attribute(ctx, driver);
                break;

            case "knx-dpt10":
                attribute = new KnxDpt10Attribute(ctx, driver);
                break;

            case "knx-dpt11":
                attribute = new KnxDpt11Attribute(ctx, driver);
                break;

            case "knx-dpt16":
                attribute = new KnxDpt16Attribute(ctx, driver);
                break;
            }

            return(attribute);
        }
Exemplo n.º 24
0
 public override IDriverNode CreateDriverNode(IDriverContext ctx)
 {
     if (ctx.NodeInstance.This2NodeTemplateNavigation.Key == "enocean-simulated")
     {
         return(new EnOceanSimulatedDevices(ctx, _driver));
     }
     _learnedDevices = new EnOceanLearnedDevices(ctx, this);
     return(_learnedDevices);
 }
Exemplo n.º 25
0
        public SonosAttribute(IDriverContext ctx, SonosDevice device, Func <Task <object> > readAction, Action <object> writeAction) : base(ctx)
        {
            _device      = device;
            _readAction  = readAction;
            _writeAction = writeAction;

            _readTimer.Elapsed += ReadTimerOnElapsed;
            _readTimer.Interval = TimeSpan.FromSeconds(2).TotalMilliseconds;
        }
Exemplo n.º 26
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            KnxLevelBase attribute = CreateDriverNode(ctx.NodeInstance.This2NodeTemplateNavigation.Key, ctx, Driver);

            if (attribute == null)
            {
                return(null);
            }

            AddChild(attribute);
            return(attribute);
        }
Exemplo n.º 27
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            IDriverNode driverNode = null;

            switch (ctx.NodeInstance.This2NodeTemplateNavigation.Key)
            {
            case "light-bulb-switch":
                driverNode = new SwitchNode(ctx,
                                            Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver);
                break;

            case "light-bulb-brightness":
                var brigthness = Accessory.CreateBrightness();
                driverNode = new LightSwitch(ctx, Driver, brigthness);
                break;

            case "light-bulb-hue":
                var hue = Accessory.CreateHue();
                driverNode = new LightSwitch(ctx, Driver, hue);
                break;

            case "power-outlet-switch":
                driverNode = new SwitchNode(ctx,
                                            Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver);
                break;

            case "contact-sensor":
                driverNode = new BaseNode(ctx,
                                          Accessory.Services[1].Characteristics
                                          .Single(a => a.Type == CharacteristicBase.ContactSensorStateType), Driver);
                break;

            case "switch":
                driverNode = new SwitchNode(ctx,
                                            Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver);
                break;

            case "temperature-sensor":
                driverNode = new BaseNode(ctx,
                                          Accessory.Services[1].Characteristics
                                          .Single(a => a.Type == CharacteristicBase.CurrentTemperatureType), Driver);
                break;

            case "switch-status":
            case "power-outlet-status":
            case "light-bulb-status":
                driverNode = new StateNode(ctx,
                                           Accessory.Services[1].Characteristics.Single(a => a.Type == CharacteristicBase.OnType), Driver);
                break;
            }

            return(driverNode);
        }
Exemplo n.º 28
0
        public override IDriver CreateDriver(IDriverContext config)
        {
            try
            {
                HomeKitServer.Init(config.Logger);
            }
            catch
            {
                // can be ignored
            }

            return(new HomeKitDriver(config));
        }
Exemplo n.º 29
0
        protected ModBus4ByteAttribute(IDriverContext driverContext) : base(driverContext)
        {
            var prop = driverContext.NodeInstance.GetProperty("modbus-byte-order");

            if (prop?.ValueInt != null)
            {
                ByteOrder = (ModBus4ByteOrder)prop.ValueInt.Value;
            }
            else
            {
                ByteOrder = ModBus4ByteOrder.AB_CD;
            }
        }
Exemplo n.º 30
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            if (ctx.NodeInstance.This2NodeTemplateNavigation.Key == "enocean-shortcut-LRN" || ctx.NodeInstance.This2NodeTemplateNavigation.Key == "enocean-shortcut-LRNB")
            {
                return(new EnOceanLrnBit(ctx, TeachInManager));
            }
            if (ctx.NodeInstance.This2NodeTemplateNavigation.Key == "enocean-shortcut-CO")
            {
                return(new EnOceanCoBit(ctx, TeachInManager));
            }

            return(new EnOceanGenericData(ctx, TeachInManager));
        }
Exemplo n.º 31
0
        /// <summary>
        ///     Sets a momento to current driver
        ///     Сохраняет состояние драйвера
        /// </summary>
        /// <param name="momento">
        ///     An instance of <see cref="IDriverMomento" /> that represents current the state of current driver
        /// </param>
        public void SetMomento(IDriverMomento momento)
        {
            if (momento == null)
            {
                throw new ArgumentNullException("momento");
            }
            var context = momento.State;

            if (context == null)
            {
                throw new ArgumentException();
            }
            this._context = context;
        }
Exemplo n.º 32
0
        protected ModBusAttribute(IDriverContext driverContext)
        {
            Table    = (ModBusTable)driverContext.NodeInstance.GetProperty("modbus-table").ValueInt.Value;
            Register = (ushort)driverContext.NodeInstance.GetProperty("modbus-register").ValueInt.Value;

            var fa = driverContext.NodeInstance.GetPropertyValue("factor", 1d);

            Factor = (double)fa;

            var off = driverContext.NodeInstance.GetPropertyValue("offset", 0d);

            Offset        = (double)off;
            DriverContext = driverContext;
        }
Exemplo n.º 33
0
        public override IDriverNode CreateDriverNode(IDriverContext ctx)
        {
            var id = ctx.NodeInstance.GetPropertyValueString(IkeaTradfriFactory.IdAddressPropertyKey);

            if (_existingDevices.ContainsKey(id))
            {
                DriverContext.Logger.LogError($"Tradfri gateway with id {id} already created");
                return(null);
            }

            _existingDevices.Add(id, ctx.NodeInstance);

            return(new IkeaTradfriGateway(ctx));
        }