Exemplo n.º 1
0
 internal InsteonDevice(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
 {
     this.network = network;
     Address      = address;
     Identity     = identity;
     ackTimer     = new Timer(PendingCommandTimerCallback, null, Timeout.Infinite, Constants.deviceAckTimeout);
 }
 internal InsteonDevice(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
 {
     this.network = network;
     Address = address;
     Identity = identity;
     ackTimer = new Timer(PendingCommandTimerCallback, null, Timeout.Infinite, Constants.deviceAckTimeout);
 }
Exemplo n.º 3
0
        public void VerifyInsteonNetworkTest()
        {
            network = new InsteonNetwork();
            var connected = network.TryConnect();

            Assert.IsTrue(connected);
            Assert.IsTrue(network.VerifyConnection());
            network.Close();
        }
Exemplo n.º 4
0
        public void SimpleConnectAnySerialPortTest()
        {
            network = new InsteonNetwork();
            var connected = network.TryConnect();

            Assert.IsTrue(connected);
            Assert.AreEqual(network.Connection.Address.Value, InsteonAddress.Parse(ConfigurationManager.AppSettings["plmIdentityTest"]).Value);
            network.Close();
        }
Exemplo n.º 5
0
        public void TearDown()
        {
            if (network != null && network.IsConnected)
            {
                network.Close();
            }

            network = null;
        }
Exemplo n.º 6
0
        private byte[] sentMessage; // bytes of last sent message, used to match the echo

        public InsteonMessenger(InsteonNetwork network)
        {
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }

            this.network         = network;
            bridge               = new InsteonNetworkBridge(this);
            ControllerProperties = new Dictionary <PropertyKey, int>();
        }
        private byte[] sentMessage; // bytes of last sent message, used to match the echo

        public InsteonMessenger(InsteonNetwork network)
        {
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }

            this.network = network;
            bridge = new InsteonNetworkBridge(this);
            ControllerProperties = new Dictionary<PropertyKey, int>();
        }
Exemplo n.º 8
0
        public void SimpleConnectKnownSerialPortTest()
        {
            InsteonConnection connection;

            Assert.IsTrue(InsteonConnection.TryParse(insteonSource, out connection));
            network = new InsteonNetwork();
            var connected = network.TryConnect(connection);

            Assert.IsTrue(connected);
            Assert.AreEqual(connection.Address.Value, InsteonAddress.Parse(ConfigurationManager.AppSettings["plmIdentityTest"]).Value);
            network.Close();
        }
Exemplo n.º 9
0
        public void TestNetworkConnection()
        {
            var network     = new InsteonNetwork();
            var connections = network.GetAvailableNetworkConnections(true);

            foreach (var connection in connections)
            {
                if (!network.IsConnected)
                {
                    network.Connect(connection);
                }
            }
        }
Exemplo n.º 10
0
        public void TestSerialConnection()
        {
            var network     = new InsteonNetwork();
            var connections = network.GetAvailableSerialConnections();

            foreach (var connection in connections)
            {
                if (!network.IsConnected)
                {
                    network.Connect(connection);
                }

                Assert.IsTrue(network.IsConnected);
            }
        }
Exemplo n.º 11
0
        public void GetLinksTest()
        {
            network = new InsteonNetwork();
            var connected = network.TryConnect();

            Assert.IsTrue(connected);
            var links = network.Controller.GetDeviceLinkRecords();

            foreach (var link in links)
            {
                Console.WriteLine(link.Address + ":" + link.RecordType);
            }

            Assert.IsNotEmpty(links);
            network.Close();
        }
        public static InsteonDevice GetDevice(this InsteonIdentity insteonIdentity, InsteonNetwork network, InsteonAddress address)
        {
            if (insteonIdentity.IsEmpty)
            {
                return new InsteonDevice(network, address, insteonIdentity);
            }

            if (DeviceTypeLookup.ContainsKey(insteonIdentity.DevCat))
            {
                if (DeviceTypeLookup[insteonIdentity.DevCat].ContainsKey(insteonIdentity.SubCat))
                {
                    return DeviceTypeLookup[insteonIdentity.DevCat][insteonIdentity.SubCat](insteonIdentity, network, address);
                }
            }

            return new InsteonDevice(network, address, insteonIdentity);
        }
        public static InsteonDevice GetDevice(this InsteonIdentity insteonIdentity, InsteonNetwork network, InsteonAddress address)
        {
            if (insteonIdentity.IsEmpty)
            {
                return(new InsteonDevice(network, address, insteonIdentity));
            }

            if (DeviceTypeLookup.ContainsKey(insteonIdentity.DevCat))
            {
                if (DeviceTypeLookup[insteonIdentity.DevCat].ContainsKey(insteonIdentity.SubCat))
                {
                    return(DeviceTypeLookup[insteonIdentity.DevCat][insteonIdentity.SubCat](insteonIdentity, network, address));
                }
            }

            return(new InsteonDevice(network, address, insteonIdentity));
        }
Exemplo n.º 14
0
        public InsteonManager(string insteonSource)
        {
            logger.Debug("Creating insteon manager");
            InsteonConnection iConnection;

            if (InsteonConnection.TryParse(insteonSource, out iConnection))
            {
                logger.DebugFormat("Parsed InsteonConnection to {0}", iConnection.ToString());
                Connection = iConnection;
            }
            else
            {
                throw new Exception("Could not create Insteon Connection type from " + insteonSource);
            }

            Network = new InsteonNetwork {
                AutoAdd = true
            };
        }
Exemplo n.º 15
0
        public void GetLinkIdentityTest()
        {
            network = new InsteonNetwork();
            var connected = network.TryConnect();

            Assert.IsTrue(connected);
            var links = network.Controller.GetDeviceLinkRecords();

            Assert.IsNotEmpty(links);


            var insteonAddresses = links.Select(l => l.Address).Distinct();


            foreach (var insteonAddress in insteonAddresses)
            {
                if (network.Devices.ContainsKey(insteonAddress))
                {
                    continue;
                }

                InsteonIdentity?id;
                if (network.Controller.TryGetLinkIdentity(insteonAddress, out id))
                {
                    if (id != null)
                    {
                        var d = network.Devices.Add(insteonAddress, id.Value);
                    }
                }
                else
                {
                    Console.WriteLine("Possibly a battery powered device.");
                }
            }

            network.Close();
        }
 internal PowerLincUsbModem(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
     : base(network, address, identity)
 {
 }
Exemplo n.º 17
0
        public void Initalize()
        {
            Trace.TraceInformation("Connecting to Insteon...");

            this.insteonNetwork = new InsteonNetwork();
            this.insteonNetwork.Close();
            this.insteonNetwork.AutoAdd = true;
            this.insteonNetwork.Connect(new InsteonConnection(InsteonConnectionType.Serial, this.usbSerial));

            if (!this.insteonNetwork.IsConnected)
            {
                Trace.TraceError("Cannot connect to Insteon.");
            }

            this.insteonNetwork.Controller.DeviceLinked +=
                (o, d) =>
            {
                Trace.TraceInformation("DeviceLinked: {0}", d.Device.Address.ToString());
                this.insteonNetwork.Controller.CancelLinkMode();
            };

            this.insteonNetwork.Controller.DeviceLinkTimeout +=
                (o, d) =>
            {
                Trace.TraceWarning("DeviceLinkTimeout");
                this.insteonNetwork.Controller.CancelLinkMode();
            };

            this.insteonNetwork.Controller.DeviceUnlinked +=
                (o, d) =>
            {
                Trace.TraceInformation("DeviceUnlinked: {0}", d.Device.Address.ToString());
                this.insteonNetwork.Controller.CancelLinkMode();
            };

            //InsteonDeviceLinkRecord[] knownLinks;
            //this.insteonNetwork.Controller.TryGetLinks(out knownLinks);
            foreach (var device in this.settings.Devices)
            {
                var d = this.insteonNetwork.Devices.Add(InsteonAddress.Parse(device.ID), new InsteonIdentity());

                d.DeviceCommandTimeout +=
                    (o, data) =>
                {
                    Trace.TraceWarning("Device command timeout. Device: " + data.Device.Address);
                };

                d.DeviceIdentified +=
                    (o, data) =>
                {
                    Trace.TraceInformation("Device identified. Device: " + data.Device.Address);
                };

                d.DeviceStatusChanged +=
                    (o, data) =>
                {
                    Trace.TraceInformation("Device status changed. Device: " + data.Device.Address + ", Status: " + data.DeviceStatus);

                    foreach (var dev in this.settings.Devices)
                    {
                        if (data.Device.Address.Value == InsteonAddress.Parse(dev.ID).Value)
                        {
                            switch (data.DeviceStatus)
                            {
                            case InsteonDeviceStatus.Brighten:
                            case InsteonDeviceStatus.Dim:
                            case InsteonDeviceStatus.FastOn:
                            case InsteonDeviceStatus.On:
                                dev.State = "On";
                                dev.Level = 255;
                                break;

                            case InsteonDeviceStatus.FastOff:
                            case InsteonDeviceStatus.Off:
                                dev.State = "Off";
                                dev.Level = 0;
                                break;

                            default:
                                dev.State = "Unknown";
                                dev.Level = 0;
                                break;
                            }

                            break;
                        }
                    }
                };
                deviceList.Add(d);

                //d.Command(InsteonDeviceCommands.StatusRequest);
            }
            //if (this.insteonNetwork.Controller.TryGetLinks(out knownLinks))
            //{
            //    foreach (var link in knownLinks)
            //    {
            //        this.debugOutput.DebugInformation("Adding device id {0}", link.Address);

            //        var d = this.insteonNetwork.Devices.Add(link.Address, new InsteonIdentity());


            //        d.DeviceCommandTimeout +=
            //            (o, data) =>
            //            {
            //                this.debugOutput.DebugInformation("Device command timeout. Device: " + data.Device.Address);
            //            };
            //        d.DeviceIdentified +=
            //            (o, data) =>
            //            {
            //                this.debugOutput.DebugInformation("Device identified. Device: " + data.Device.Address);
            //            };
            //        d.DeviceStatusChanged +=
            //            (o, data) =>
            //            {
            //                this.debugOutput.DebugInformation("Device status changed. Device: " + data.Device.Address + ", Status: " + data.DeviceStatus);

            //                foreach (var de in this.settings.Devices)
            //                    if (GetInsteonDevice(de.ID) != null)
            //                    {
            //                        de.State = data.DeviceStatus == InsteonDeviceStatus.On ? "On" : "Off";
            //                        de.Level = (byte)(data.DeviceStatus == InsteonDeviceStatus.On ? 255 : 0);
            //                        break;
            //                    }
            //            };

            //        //d.Command(InsteonDeviceCommands.StatusRequest);
            //    }
            //}
            //else
            //{
            //    this.debugOutput.DebugError("Cannot get links");
            //}
        }
Exemplo n.º 18
0
 internal IoLinc(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
     : base(network, address, identity)
 {
 }
Exemplo n.º 19
0
 internal IoLinc(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
     : base(network, address, identity)
 {
 }
Exemplo n.º 20
0
 internal MiniRemote(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity, int buttonCount)
     : base(network, address, identity)
 {
     NumberOfButtons = buttonCount;
 }
Exemplo n.º 21
0
 internal LeakSensor(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
     : base(network, address, identity)
 {
 }
 internal InsteonDeviceList(InsteonNetwork network)
 {
     this.network = network;
 }
Exemplo n.º 23
0
 internal MotionSensor(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
     : base(network, address, identity)
 {
 }
 internal DimmableLighting(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
     : base(network, address, identity)
 {
 }
 internal SwitchedLighting(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity) : base(network, address, identity) { }
 internal SwitchedLighting(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity) : base(network, address, identity)
 {
 }
        internal DimmableLighting(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity)
            : base(network, address, identity)
        {

        }
Exemplo n.º 28
0
 public NetworkService(InsteonNetwork insteonNetwork)
 {
     Network = insteonNetwork;
 }
Exemplo n.º 29
0
 internal MiniRemote(InsteonNetwork network, InsteonAddress address, InsteonIdentity identity, int buttonCount)
     : base(network, address, identity)
 {
     NumberOfButtons = buttonCount;
 }