private void OnGatewayRemoveNode(Gateways.MySensors.Node node)
        {
            MySensorsNode oldNode = GetMySensorsNode(node.Id);

            if (oldNode != null)
            {
                engine.RemoveNode(oldNode);
            }
        }
        public MySensorsNodeInput GetMySensorsNodeInput(int nodeId, int sensorId)
        {
            MySensorsNode oldNode = GetMySensorsNode(nodeId);

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

            return(oldNode.Inputs
                   .OfType <MySensorsNodeInput>()
                   .FirstOrDefault(input => input.sensorId == sensorId));
        }
        private void OnEngineRemoveNode(Node node)
        {
            if (!(node is MySensorsNode))
            {
                return;
            }

            MySensorsNode n = (MySensorsNode)node;

            if (gateway.GetNode(n.nodeId) != null)
            {
                gateway.RemoveNode(n.nodeId);
            }
        }
        private void CreateOrUpdateNode(Gateways.MySensors.Node node)
        {
            MySensorsNode oldNode = GetMySensorsNode(node.Id);

            if (oldNode == null)
            {
                MySensorsNode newMySensorsNode = new MySensorsNode(node);
                engine.AddNode(newMySensorsNode);
            }
            else
            {
                oldNode.Settings["Name"].Value = node.GetSimpleName2();
                engine.UpdateNodeInEditor(oldNode);
                engine.UpdateNodeInDb(oldNode);
            }
        }
        private void CreateOrUpdateSensor(Sensor sensor)
        {
            MySensorsNodeOutput output = GetMySensorsNodeOutput(sensor);

            if (output == null)
            {
                MySensorsNode node = GetMySensorsNode(sensor.nodeId);
                node.AddInputAndOutput(sensor);
                engine.UpdateNodeInEditor(node);
                engine.UpdateNodeInDb(node);
            }
            else
            {
                engine.UpdateOutput(output.Id, sensor.state, sensor.GetSimpleName3());
            }
        }
        public List <MySensorsNode> CreateAndAddMySensorsNodes()
        {
            var list = new List <MySensorsNode>();

            foreach (var node in gateway.GetNodes())
            {
                if (GetMySensorsNode(node.Id) != null)
                {
                    continue;
                }

                MySensorsNode newMySensorsNode = new MySensorsNode(node);
                list.Add(newMySensorsNode);
                engine.AddNode(newMySensorsNode);
            }
            return(list);
        }
 private void CreateOrUpdateNode(Gateways.MySensors.Node node)
 {
     MySensorsNode oldNode = GetMySensorsNode(node.Id);
     if (oldNode == null)
     {
         MySensorsNode newMySensorsNode = new MySensorsNode(node);
         engine.AddNode(newMySensorsNode);
     }
     else
     {
         oldNode.Settings["Name"].Value = node.GetSimpleName2();
         engine.UpdateNodeInEditor(oldNode);
         engine.UpdateNodeInDb(oldNode);
     }
 }
        public List<MySensorsNode> CreateAndAddMySensorsNodes()
        {
            var list = new List<MySensorsNode>();

            foreach (var node in gateway.GetNodes())
            {
                if (GetMySensorsNode(node.Id) != null)
                    continue;

                MySensorsNode newMySensorsNode = new MySensorsNode(node);
                list.Add(newMySensorsNode);
                engine.AddNode(newMySensorsNode);
            }
            return list;
        }
        private void OnNodeBatteryUpdated(Gateways.MySensors.Node node)
        {
            MySensorsNode n = GetMySensorsNode(node.Id);

            n?.UpdateBattery(node.batteryLevel);
        }