use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.
the class ApplicationScheduler method mood.
@Scheduled(fixedDelay = 300000)
public void mood() {
logger.debug("mood trigger");
// mood
Application application = checkNotNull(applicationManager.getApplication(MOOD_APIKEY));
Query<Nabaztag> query = nabaztagDAO.createQuery().filter("applicationConfigList.applicationStoreApikey", MOOD_APIKEY);
Iterator<Nabaztag> iterator = nabaztagDAO.find(query).iterator();
while (iterator.hasNext()) {
Nabaztag nabaztag = iterator.next();
Status status = connectionManager.get(nabaztag.getMacAddress());
if (status != null && status.isIdle()) {
if (rand.nextInt(4) == 0) {
try {
application.onStartup(nabaztag, findConfig(MOOD_APIKEY, nabaztag.getApplicationConfigList()));
} catch (Exception e) {
logger.debug("cannot send message", e);
}
}
}
}
}
use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.
the class ApplicationScheduler method scheduled.
@Scheduled(cron = "0 * * * * *")
public void scheduled() {
logger.debug("scheduled");
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int day = cal.get(Calendar.DAY_OF_WEEK);
String scheduleKey = String.format("%02d:%02d-%d", hour, minute, day);
logger.debug("scheduleKey: {}", scheduleKey);
Query<Nabaztag> queryWakeUp = nabaztagDAO.createQuery().filter("wakeup", scheduleKey);
sendToAll(queryWakeUp, new SleepPacket(SleepPacket.Action.WakeUp));
Query<Nabaztag> querySleep = nabaztagDAO.createQuery().filter("sleep", scheduleKey);
sendToAll(querySleep, new SleepPacket(SleepPacket.Action.Sleep));
}
use of com.nabalive.data.core.model.Nabaztag in project NabAlive by jcheype.
the class ConnectionWelcome method onEvent.
@Override
public void onEvent(String sender, Event event) throws Exception {
logger.debug("event type {}", event.type);
logger.debug("event type {}", event.content);
if (event.type == Event.Type.UNBIND_RESOURCE && event.content.contains("<resource>boot</resource></unbind>")) {
Nabaztag nabaztag = nabaztagDAO.findOne("macAddress", sender);
logger.debug("WELCOME: unbind {}", nabaztag);
messageService.sendMessage(sender, new PingPacket(60));
if (nabaztag == null) {
logger.debug("WELCOME: SENDING SOUND");
String command = "CH http://www.nabalive.com/api/chor/rand/5\nMW\n" + "ST " + WELCOME_URL + "\nMW\n";
messageService.sendMessage(sender, command);
} else {
boolean isSleep = checkSleep(nabaztag);
logger.debug("WELCOME: ISSLEEP :" + isSleep);
if (isSleep) {
logger.debug("WELCOME: SENDING SLEEP");
messageService.sendMessage(nabaztag.getMacAddress(), new SleepPacket(SleepPacket.Action.Sleep));
}
}
}
}
Aggregations