public void AlarmParDefaut() { var ParamDef = new Alarme(); ParamDef.IsRinging = false; ParamDef.AlarmHour = -1; ParamDef.AlarmMinutes = -1; ChangeAlarm(ParamDef); }
public void ModeAuto() { TimeAndPlace WakeUp = GetWakeUpHour(); TimeSpan prep_time = new TimeSpan(); string title, body; try { prep_time = new TimeSpan(0, int.Parse(PackageHost.GetSettingValue("TpsPrep")), 0); } catch { prep_time = new TimeSpan(0, 45, 0); PackageHost.WriteWarn("Paramètre du temps de préparation non récupéré, le temps de 45mn sera considéré"); } Alarme NewAlarm = new Alarme(); NewAlarm.IsRinging = false; NewAlarm.TimeFirstEvent = WakeUp.Time.ToString(); if (WakeUp.Time.Subtract(DateTime.Now) < new TimeSpan(1, 0, 0, 0)) //Si le réveil doit sonner dans + de 24h on active pas encore l'alarme et on attends le refresh journalier { if (WakeUp.TimeTraffic != new TimeSpan()) { WakeUp.Time = WakeUp.Time.Subtract(prep_time + WakeUp.TimeTraffic); NewAlarm.TimeTraffic = WakeUp.TimeTraffic.ToString(); NewAlarm.AlarmHour = WakeUp.Time.Hour; NewAlarm.AlarmMinutes = WakeUp.Time.Minute; title = "Alarme en mode automatique"; body = string.Format("L'alarme sonnera à {0}:{1}", NewAlarm.AlarmHour.ToString("00"), NewAlarm.AlarmMinutes.ToString("00")); PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String }); ChangeAlarm(NewAlarm); return; } else { title = "Erreur temps de trajet"; body = "Impossible de récuperer le temps de trajet, le temps de trajet ne sera pas pris en compte"; PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String }); WakeUp.Time = WakeUp.Time.Subtract(prep_time); NewAlarm.AlarmHour = WakeUp.Time.Hour; NewAlarm.AlarmMinutes = WakeUp.Time.Minute; NewAlarm.TimeTraffic = new TimeSpan().ToString(); ChangeAlarm(NewAlarm); return; } } else { PackageHost.WriteInfo("Pas de réveil automatique prévu d'ici les 24h prochaines heures !"); } }
private void Ring() { PackageHost.WriteInfo("Bip Bip Bip"); var NextAlarm = new Alarme(); NextAlarm.IsRinging = true; NextAlarm.AlarmHour = DateTime.Now.Hour; NextAlarm.AlarmMinutes = DateTime.Now.Minute; NextAlarm.TimeFirstEvent = Alarm.DynamicValue.TimeFirstEvent.ToString(); NextAlarm.TimeTraffic = Alarm.DynamicValue.TimeTraffic.ToString(); ChangeAlarm(NextAlarm); return; }
private void Events_ValueChanged(object sender, StateObjectChangedEventArgs e) { foreach (var event_ in e.NewState.DynamicValue) { //PackageHost.WriteInfo("{0} // {1}", DateTime.Parse(event_.DateDebut.ToString()) == DateTime.Parse(Alarm.DynamicValue.TimeFirstEvent.ToString()), TimeSpan.Parse(event_.TimeTrafficFromHouse.ToString()) != TimeSpan.Parse(Alarm.DynamicValue.TimeTraffic.ToString())); if (DateTime.Parse(event_.DateDebut.ToString()) > DateTime.Now && TimeSpan.Parse(event_.TimeTrafficFromHouse.ToString()) != TimeSpan.Parse(Alarm.DynamicValue.TimeTraffic.ToString())) { // PackageHost.WriteInfo("{0},{1}", TimeSpan.Parse(event_.TimeTrafficFromHouse.ToString()), TimeSpan.Parse(Alarm.Value.DynamicValue.TimeTraffic.ToString())); TimeSpan diff_traffic = TimeSpan.Parse(event_.TimeTrafficFromHouse.ToString()) - TimeSpan.Parse(Alarm.Value.DynamicValue.TimeTraffic.ToString()); //Nouveau temps - ancien temps PackageHost.WriteInfo("Diff traffic {0}", diff_traffic); TimeSpan BeforeAlarm = (DateTime.Parse(Alarm.DynamicValue.TimeFirstEvent.ToString()) - new TimeSpan(0, int.Parse(PackageHost.GetSettingValue("TpsPrep")), 0) - TimeSpan.Parse(event_.TimeTrafficFromHouse.ToString())).Subtract(DateTime.Now); PackageHost.WriteDebug("Before alarm {0}", BeforeAlarm); if (BeforeAlarm > diff_traffic)//Si le temps de trafic augmente on réveille plus tôt sans dépasser l'heure { Alarme newAlarm = new Alarme(); newAlarm.AlarmMinutes = int.Parse(Alarm.Value.DynamicValue.AlarmMinutes.ToString()) - diff_traffic.Minutes; PackageHost.WriteDebug("AlarmMinutes {0}", newAlarm.AlarmMinutes); if (newAlarm.AlarmMinutes > 60) { newAlarm.AlarmHour = (int.Parse(Alarm.Value.DynamicValue.AlarmHour.ToString()) - diff_traffic.Hours + newAlarm.AlarmMinutes / 60) % 24; newAlarm.AlarmMinutes = newAlarm.AlarmMinutes % 60; } if (newAlarm.AlarmMinutes < 0) { newAlarm.AlarmHour = (int.Parse(Alarm.Value.DynamicValue.AlarmHour.ToString()) - diff_traffic.Hours + (newAlarm.AlarmMinutes - 60 / 60)) % 24; newAlarm.AlarmMinutes = newAlarm.AlarmMinutes % 60; } else { newAlarm.AlarmHour = (int.Parse(Alarm.Value.DynamicValue.AlarmHour.ToString()) - diff_traffic.Hours) % 24; } newAlarm.IsRinging = false; PackageHost.WriteDebug("Is ringing : {0}", newAlarm.IsRinging); newAlarm.TimeFirstEvent = event_.DateDebut.ToString(); PackageHost.WriteDebug("Time 1st event {0}", newAlarm.TimeFirstEvent); newAlarm.TimeTraffic = event_.TimeTrafficFromHouse.ToString(); PackageHost.WriteDebug("New time traffic {0}", newAlarm.TimeTraffic); ChangeAlarm(newAlarm); return; } return; } } }
public void ModeManuel() { if (int.Parse(ParametresServeur.DynamicValue.AlarmHour.ToString()) > 0 && int.Parse(ParametresServeur.DynamicValue.AlarmMinutes.ToString()) > 0) { PackageHost.WriteInfo("Mode de réveil = 1"); Alarme NewAlarm = new Alarme(); NewAlarm.IsRinging = false; NewAlarm.AlarmHour = int.Parse(ParametresServeur.DynamicValue.ManualAlarmHour.ToString()); NewAlarm.AlarmMinutes = int.Parse(ParametresServeur.DynamicValue.ManualAlarmMinute.ToString()); var title = "Alarme en mode manuel"; var body = string.Format("L'alarme sonnera à {0}:{1}", NewAlarm.AlarmHour.ToString("00"), NewAlarm.AlarmMinutes.ToString("00")); PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String }); ChangeAlarm(NewAlarm); return; } else { var title = "Erreur mode manuel"; var body = string.Format("L'heure entrée pour le mode manuel n'est pas correct !"); PackageHost.SendMessage(MessageScope.Create("PushBullet"), "PushNote", new object[] { title as System.String, body as System.String }); } }
public void SnoozeAlarm() { Alarme newAlarm = new Alarme(); int SnoozeMinutes; try { if (bool.Parse(ParametresServeur.DynamicValue.BigSleeper.ToString())) { SnoozeMinutes = int.Parse(PackageHost.GetSettingValue("Snooze").ToString()); } else { SnoozeMinutes = int.Parse(PackageHost.GetSettingValue("SnoozeBigSleeper").ToString()); } } catch (Exception e) { PackageHost.WriteWarn(e); SnoozeMinutes = 5; } if (int.Parse(Alarm.Value.DynamicValue.AlarmMinutes.ToString()) >= 55) { newAlarm.AlarmHour = int.Parse(Alarm.Value.DynamicValue.AlarmHour.ToString()) + 1; } else { newAlarm.AlarmHour = int.Parse(Alarm.Value.DynamicValue.AlarmHour.ToString()); } newAlarm.AlarmMinutes = (int.Parse(Alarm.Value.DynamicValue.AlarmMinutes.ToString()) + 5) % 60; newAlarm.IsRinging = false; newAlarm.TimeFirstEvent = Alarm.Value.DynamicValue.TimeFirstEvent; newAlarm.TimeTraffic = Alarm.Value.DynamicValue.TimeTraffic; ChangeAlarm(newAlarm); }
public void ChangeAlarm(Alarme newAlarm) { PackageHost.PushStateObject("Alarm", newAlarm); System.Threading.Thread.Sleep(1000); }