public SaunaState Post(SaunaState item) { // find the room by a given room ID (SaunaStateData.Sauna) Room sauna = Program.Rooms.Items.Where(s => s.Id == item.Sauna).FirstOrDefault(); if (sauna == null) { throw new ApplicationException("Room not found: " + item.Sauna); } // return the room state on the given DateTime return ((Sauna)sauna).GetState(item.DateTime); }
public SaunaState GetState(DateTime dt) { SaunaState state = new SaunaState(); //the sauna is off state.Sauna = this.Id; state.DateTime = dt; state.Stove = "Off"; state.Light = "Off"; state.Temperature = NORMAL_TEMP; SaunaConfiguration conf = getMatchingConfiguration(dt); if (conf == null) { return state; } state.Temperature = getTemperature(conf, dt); //turn the light on when it's hot enough state.Light = state.Temperature > 60 ? "On" : "Off"; //turn the stove on / off if it's too cold / hot state.Stove = state.Temperature < MAX_TEMP ? "On" : "Off"; DateTime offTime = parseTime(conf.Off, dt.ToString(DATE)); if (dt >= offTime) { state.Light = "Off"; state.Stove = "Off"; } return state; }