public Device(IDeviceConnection deviceConnectionIn, IDeviceCommunication deviceCommunicationIn)
 {
     deviceConnection = deviceConnectionIn;
     deviceConnection.SetCallback(GetHost, SetDeviceState, OnReceiveMessage);
     deviceCommunication = deviceCommunicationIn;
     deviceCommunication.SetCallback(SetDeviceState, OnVolumeUpdate, deviceConnection.SendMessage, GetDeviceState, IsConnected, deviceConnection.IsConnected, GetHost);
     deviceState   = DeviceState.NotConnected;
     volumeSetting = new Volume
     {
         controlType  = "attenuation",
         level        = 0.0f,
         muted        = false,
         stepInterval = 0.05f
     };
 }
        /// <summary>
        /// Initialize a device.
        /// </summary>
        /// <param name="discoveredDeviceIn">the discovered device</param>
        public void Initialize(DiscoveredDevice discoveredDeviceIn)
        {
            if (discoveredDevice == null || deviceCommunication == null || deviceConnection == null)
            {
                return;
            }

            logger.Log($"Discovered device: {JsonConvert.SerializeObject(discoveredDeviceIn)}");
            if (discoveredDeviceIn.Headers != null)
            {
                discoveredDevice.Headers = discoveredDeviceIn.Headers;
            }
            if (discoveredDeviceIn.IPAddress != null)
            {
                discoveredDevice.IPAddress = discoveredDeviceIn.IPAddress;
            }
            if (discoveredDeviceIn.Name != null)
            {
                discoveredDevice.Name = discoveredDeviceIn.Name;
            }
            if (discoveredDeviceIn.Port != 0)
            {
                discoveredDevice.Port = discoveredDeviceIn.Port;
            }
            if (discoveredDeviceIn.Protocol != null)
            {
                discoveredDevice.Protocol = discoveredDeviceIn.Protocol;
            }
            deviceCommunication.SetCallback(SetDeviceState,
                                            OnVolumeUpdate,
                                            deviceConnection.SendMessage,
                                            GetDeviceState,
                                            IsConnected,
                                            deviceConnection.IsConnected,
                                            GetHost,
                                            GetPort,
                                            SendSilence,
                                            WasPlayingWhenStopped);
            deviceConnection.SetPort(discoveredDevice.Port);
            OnGetStatus();
            volumeSetting = new Volume
            {
                controlType  = "attenuation",
                level        = 0.0f,
                muted        = false,
                stepInterval = 0.05f
            };
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize a device.
        /// </summary>
        /// <param name="discoveredDeviceIn">the discovered device</param>
        public void Initialize(DiscoveredDevice discoveredDeviceIn, Action <DeviceEureka> setDeviceInformationCallbackIn
                               , Action <IDevice> stopGroupIn, Action <Action, CancellationTokenSource> startTaskIn, Func <IDevice, bool> isGroupStatusBlankIn
                               , Action <bool> autoMuteIn)
        {
            setDeviceInformationCallback = setDeviceInformationCallbackIn;
            //stopGroup = stopGroupIn;
            startTask          = startTaskIn;
            isGroupStatusBlank = isGroupStatusBlankIn;
            autoMute           = autoMuteIn;

            if (discoveredDevice == null || deviceCommunication == null || deviceConnection == null ||
                discoveredDeviceIn == null || setDeviceInformationCallbackIn == null || stopGroupIn == null)
            {
                return;
            }

            var ipChanged = discoveredDevice.IPAddress != discoveredDeviceIn.IPAddress;

            // Logging
            if (ipChanged ||
                discoveredDevice.Name != discoveredDeviceIn.Name ||
                discoveredDevice.Port != discoveredDeviceIn.Port ||
                JsonConvert.SerializeObject(discoveredDevice.Eureka?.Multizone?.Groups)
                != JsonConvert.SerializeObject(discoveredDeviceIn.Eureka?.Multizone?.Groups))
            {
                logger.Log($"Discovered device: {discoveredDeviceIn?.Name} {discoveredDeviceIn?.IPAddress}:{discoveredDeviceIn?.Port} {JsonConvert.SerializeObject(discoveredDeviceIn?.Eureka?.Multizone?.Groups)} {discoveredDeviceIn?.Id}");
            }

            if (discoveredDeviceIn.Headers != null)
            {
                discoveredDevice.Headers = discoveredDeviceIn.Headers;
            }
            if (discoveredDeviceIn.IPAddress != null)
            {
                discoveredDevice.IPAddress = discoveredDeviceIn.IPAddress;
            }
            if (discoveredDeviceIn.MACAddress != null)
            {
                discoveredDevice.MACAddress = discoveredDeviceIn.MACAddress;
            }
            if (discoveredDeviceIn.Id != null)
            {
                discoveredDevice.Id = discoveredDeviceIn.Id;
            }
            if (discoveredDeviceIn.Name != null)
            {
                discoveredDevice.Name = discoveredDeviceIn.Name;
            }
            if (discoveredDeviceIn.Port != 0)
            {
                discoveredDevice.Port = discoveredDeviceIn.Port;
            }
            if (discoveredDeviceIn.Protocol != null)
            {
                discoveredDevice.Protocol = discoveredDeviceIn.Protocol;
            }
            if (discoveredDeviceIn.Usn != null)
            {
                discoveredDevice.Usn = discoveredDeviceIn.Usn;
            }
            discoveredDevice.AddedByDeviceInfo = discoveredDeviceIn.AddedByDeviceInfo;
            if (discoveredDeviceIn.Eureka != null)
            {
                discoveredDevice.Eureka = discoveredDeviceIn.Eureka;
            }
            if (discoveredDeviceIn.Group != null)
            {
                discoveredDevice.Group = discoveredDeviceIn.Group;
            }

            deviceCommunication.SetCallback(this, deviceConnection.SendMessage, deviceConnection.IsConnected);
            if (ipChanged && GetDeviceState() == DeviceState.Playing)
            {
                ResumePlaying();
            }
        }
        /// <summary>
        /// Initialize a device.
        /// </summary>
        /// <param name="discoveredDeviceIn">the discovered device</param>
        public void Initialize(DiscoveredDevice discoveredDeviceIn, Action <DeviceEureka> setDeviceInformationCallbackIn)
        {
            if (discoveredDevice == null || deviceCommunication == null || deviceConnection == null)
            {
                return;
            }

            var ipChanged = discoveredDevice.IPAddress != discoveredDeviceIn.IPAddress;

            // Logging
            if (ipChanged ||
                discoveredDevice.Name != discoveredDeviceIn.Name ||
                discoveredDevice.Port != discoveredDeviceIn.Port ||
                JsonConvert.SerializeObject(discoveredDevice.Eureka?.Multizone?.Groups)
                != JsonConvert.SerializeObject(discoveredDeviceIn.Eureka?.Multizone?.Groups))
            {
                logger.Log($"Discovered device: {discoveredDeviceIn.Name} {discoveredDeviceIn.IPAddress}:{discoveredDeviceIn.Port} {JsonConvert.SerializeObject(discoveredDeviceIn.Eureka.Multizone.Groups)}");
            }

            if (discoveredDeviceIn.Headers != null)
            {
                discoveredDevice.Headers = discoveredDeviceIn.Headers;
            }
            if (discoveredDeviceIn.IPAddress != null)
            {
                discoveredDevice.IPAddress = discoveredDeviceIn.IPAddress;
            }
            if (discoveredDeviceIn.Name != null)
            {
                discoveredDevice.Name = discoveredDeviceIn.Name;
            }
            if (discoveredDeviceIn.Port != 0)
            {
                discoveredDevice.Port = discoveredDeviceIn.Port;
            }
            if (discoveredDeviceIn.Protocol != null)
            {
                discoveredDevice.Protocol = discoveredDeviceIn.Protocol;
            }
            if (discoveredDeviceIn.Usn != null)
            {
                discoveredDevice.Usn = discoveredDeviceIn.Usn;
            }
            discoveredDevice.AddedByDeviceInfo = discoveredDeviceIn.AddedByDeviceInfo;
            if (discoveredDeviceIn.Eureka != null)
            {
                discoveredDevice.Eureka = discoveredDeviceIn.Eureka;
            }
            if (discoveredDeviceIn.Group != null)
            {
                discoveredDevice.Group = discoveredDeviceIn.Group;
            }

            deviceCommunication.SetCallback(this, deviceConnection.SendMessage, deviceConnection.IsConnected);
            if (!IsGroup() || (IsGroup() && discoveredDevice.AddedByDeviceInfo))
            {
                OnGetStatus();
            }
            setDeviceInformationCallback = setDeviceInformationCallbackIn;
            if (ipChanged && deviceState == DeviceState.Playing)
            {
                ResumePlaying();
            }
        }