/// <summary> /// Calculate IRoomConfig.RoomStatus property based on last events /// </summary> /// <param name="roomConfig"></param> /// <param name="sensor"></param> private void UpdateRoomStatus(IRoomConfig roomConfig, IRoomSensor sensor) { if (roomConfig == null) { return; // Nothing to do; } // If this is PiR a sensor telemetry IRoomSensor piRSensor = null; if (sensor != null && NotificationEventSchema.PirSensorValueLabel.Equals(sensor.Telemetry)) { piRSensor = sensor; } else if (roomConfig.RoomSensors != null) { // If Not - extract sensor from Room Config piRSensor = roomConfig.RoomSensors.FirstOrDefault <IRoomSensor>(s => NotificationEventSchema.PirSensorValueLabel.Equals(s.Telemetry)); } DateTime leeWayEndTime = DateTime.Now.AddSeconds(roomConfig.EventLeewaySeconds); // Remove outdated appointments // TODO? Perform this check for all rooms ? if (roomConfig.CurrentAppointment != null && leeWayEndTime >= DateTime.Parse(roomConfig.CurrentAppointment.EndTime)) { // Check if room appointment expired roomConfig.CurrentAppointment = null; } double PiR = -1.0; if (piRSensor != null && piRSensor.LastMeasurement != null)// PiR sensor changed { Double.TryParse(piRSensor.LastMeasurement.Value, out PiR); } if (PiR > 0.0) //Presense detected { if (roomConfig.CurrentAppointment != null) { roomConfig.RoomStatus = RoomStatus.RoomScheduledAndOccupied; } else { roomConfig.RoomStatus = RoomStatus.RoomOccupied; } } else // No presence in the room { if (roomConfig.CurrentAppointment != null) { roomConfig.RoomStatus = RoomStatus.RoomScheduled; } else { roomConfig.RoomStatus = RoomStatus.RoomFree; } } }
internal void OnRoomSensorChanged(object sender, IRoomSensor e) { var roomConfig = sender as RoomConfig; if (roomConfig == null) { return; } LevelData.UpdateRoomConfig(roomConfig); }
public void OnRoomSensorChanged(object sender, IRoomSensor e) { SetRoomStatus(sender as IRoomConfig); }