public string GetSensorMessage(SensorRefactoredSome sensor)
        {
            string message = "default";

            if (!sensor.IsTripped())
            {
                if (sensor.MyType().Equals(SensorRefactoredSome.DOOR))
                {
                    return(sensor.GetLocation() + " is closed");
                }
                else if (sensor.MyType().Equals(SensorRefactoredSome.WINDOW))
                {
                    return(sensor.GetLocation() + " is sealed");
                }
                else if (sensor.MyType().Equals(SensorRefactoredSome.MOTION))
                {
                    return(sensor.GetLocation() + " is motionless");
                }
                else if (sensor.MyType().Equals(SensorRefactoredSome.FIRE))
                {
                    return(sensor.GetLocation() + " temperature is normal");
                }
            }
            else
            {
                if (sensor.MyType().Equals(SensorRefactoredSome.DOOR))
                {
                    return(sensor.GetLocation() + " is open");
                }
                else if (sensor.MyType().Equals(SensorRefactoredSome.WINDOW))
                {
                    return(sensor.GetLocation() + " is ajar");
                }
                else if (sensor.MyType().Equals(SensorRefactoredSome.MOTION))
                {
                    return("Motion detected in " + sensor.GetLocation());
                }
                else if (sensor.MyType().Equals(SensorRefactoredSome.FIRE))
                {
                    return(sensor.GetLocation() + " is on FIRE!");
                }
            }
            return(message);
        }
        public void ParseRadioBroadcast(String packet)
        {
            //parse the packet
            string[] tokens = packet.Split(',');
            string   id     = tokens[0];
            string   status = tokens[1];

            // find sensor with id
            SensorRefactoredSome sensor = null;

            foreach (SensorRefactoredSome s in sensors)
            {
                if (s.GetId().Equals(id))
                {
                    sensor = s;
                    break;
                }
            }

            //trip or reset sensor
            if (sensor != null)
            {
                if ("TRIPPED".Equals(status))
                {
                    sensor.Trip();
                }
                else
                {
                    sensor.Reset();
                }
            }

            //get the message from the sensor and display it
            string message = GetSensorMessage(sensor);

            view.ShowMessage(message);

            // sound the alarm if armed
            if (IsArmed())
            {
                audibleAlarm.Sound();
            }

            // check if a sensor test is running and adjust status
            if (runningSensorTest)
            {
                if ("TRIPPED".Equals(status))
                {
                    sensorTestStatusMap.Add(id, PASS);
                }

                // check to see if test is complete
                bool done = true;
                foreach (string testStatus in sensorTestStatusMap.Values)
                {
                    if (PENDING.Equals(testStatus))
                    {
                        done = false;
                        break;
                    }
                }

                //terminate test if complete
                if (done)
                {
                    TerminateSensorTest();
                }
            }
        }
 public void RegisterSensor(SensorRefactoredSome sensor)
 {
     sensors.Add(sensor);
 }