public static void ToggleLight(int lightId, int action) { try { using (var dbContext = new AutoLuminosityDataDataContext()) { string lightAction = string.Empty; if (action == 1) { lightAction = "on"; } else if (action == 2) { lightAction = "off"; } string jsonRequest = "{ \"power\": \"" + lightAction + "\" }"; var light = dbContext.AutoLuminosity_Lights.FirstOrDefault(i => i.LightId == lightId); if (light != null) { LifxConnector.ToggleLight(light.LightExternalId, jsonRequest); } } } catch (Exception ex) { } }
public static void ExecuteSchedule(int scheduleId) { try { using (var dbContext = new AutoLuminosityDataDataContext()) { var schedule = dbContext.AutoLuminosity_Schedules.FirstOrDefault(i => i.ScheduleId == scheduleId); if (schedule != null) { string action = string.Empty; if (schedule.ScheduleAction == 1) { action = "on"; } else if (schedule.ScheduleAction == 2) { action = "off"; } string jsonRequest = "{ \"power\": \"" + action + "\" }"; if (schedule.ScheduleType == ScheduleType.Light) { var light = dbContext.AutoLuminosity_Lights.FirstOrDefault(i => i.LightId == schedule.ScheduleEntityId); if (light != null) { LifxConnector.ToggleLight(light.LightExternalId, jsonRequest); } } else if (schedule.ScheduleType == ScheduleType.Room) { var room = dbContext.AutoLuminosity_Rooms.FirstOrDefault(i => i.RoomId == schedule.ScheduleEntityId); if (room != null) { LifxConnector.ToggleRoom(room.RoomExternalId, jsonRequest); } } } } } catch (Exception ex) { } }