Exemple #1
0
        private (bool?IsNecessary, string content) GetContent(HueDeviceDto currentDevice, HueLightStatePutDto state, bool withoutOn)
        {
            if (TryParseHueDeviceType(currentDevice, out var deviceType))
            {
                var contentDto = this.MapToType(deviceType, state, withoutOn);

                if (contentDto == null)
                {
                    this._logger?.LogError($"{nameof(LightStateHandler)} hat den DeviceType {currentDevice.Type} nicht implementiert");

                    return(false, string.Empty);
                }

                else
                {
                    try
                    {
                        return(true, LowerCaseSerializer.SerializeObject(contentDto));
                    }

                    catch (Exception ex)
                    {
                        this._logger?.LogError(ex, "Während der Serialisierung trat ein Fehler auf");

                        return(null, string.Empty);
                    }
                }
            }

            else
            {
                this._logger?.LogError($"Light {currentDevice.Name} hat einen ungültigen Type {currentDevice.Type}");
                return(null, string.Empty);
            }
        }
Exemple #2
0
        public static bool TryParseHueDeviceType(HueDeviceDto hueDevice, out EHueDeviceType deviceType)
        {
            if (!string.IsNullOrEmpty(hueDevice.Type))
            {
                bool result = false;
                switch (hueDevice.Type)
                {
                case LightType_ColorTemperatureLight:
                    deviceType = EHueDeviceType.Temperature_Light;
                    result     = true;
                    break;

                case LightType_ExtendedColorLight:
                    deviceType = EHueDeviceType.Extended_Color_Light;
                    result     = true;
                    break;

                default:
                    deviceType = EHueDeviceType.Unkown;
                    result     = false;
                    break;
                }


                return(result);
            }

            else
            {
                deviceType = EHueDeviceType.Unkown;
                return(false);
            }
        }
Exemple #3
0
        public (bool?IsNecessary, string content) GetSwitchStateContent(HueDeviceDto currentDevice,
                                                                        HueLightStatePutDto state)
        {
            if (state.On != currentDevice.State.On)
            {
                return(this.GetContent(currentDevice, state, false));
            }

            else
            {
                if (currentDevice.State.On) // Soll laut Api nicht immer mit On auf True schicken wenn dieser bereits True ist
                {
                    return(this.GetContent(currentDevice, state, true));
                }

                else
                {
                    this._logger?.LogDebug($"Aktueller Status von Light {state.Id} " +
                                           $"hat bereits den gewünschten Status {state.On}");

                    return(false, string.Empty);
                }
            }
        }