Ejemplo n.º 1
0
        public async Task<Scene> CreateSceneAsync(Scene scene)
        {
            if (scene.Schedule == null) scene.Schedule = new Schedule();
            if (scene.Sequence == null) scene.Sequence = new Sequence();
            Scene sceneToCreate = Context.Scenes.Add(scene);

            await SaveAsync();
            return sceneToCreate;
        }
Ejemplo n.º 2
0
        public async Task<Scene> UpdateSceneAsync(Scene scene)
        {
            Scene sceneToUpdate = await GetSceneAsync(scene.UserName, scene.Id);
            if (sceneToUpdate == null)
                return null;

            if (scene.Name != null) sceneToUpdate.Name = scene.Name;
            if (scene.DeviceSettings != null) sceneToUpdate.DeviceSettings = scene.DeviceSettings;
            if (scene.Schedule != null) sceneToUpdate.Schedule = scene.Schedule;
            if (scene.Sequence != null) sceneToUpdate.Sequence = scene.Sequence;

            await SaveAsync();
            return sceneToUpdate;
        }
Ejemplo n.º 3
0
        private async Task BindSceneSettingsToDevices(Scene scene)
        {
            List<Device> usedDevices =
                (await _deviceRepository.GetDevicesAsync(User.Identity.Name, scene.DeviceSettings.Select(s => s.Device.Id))).ToList();

            foreach (DeviceSetting setting in scene.DeviceSettings)
            {
                setting.Device = usedDevices.SingleOrDefault(a => a.Id == setting.Device.Id);
                if (!setting.IsValid())
                {
                    throw new Exception($"Invalid setting for device {setting.Device.Id}");
                }
            }
        }