public ActionResult <RelayDevice> relayChanged(int areaId, string deviceName, int swState)
        {
            var clientIP = HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress.ToString();

            lock (clientIP)
            {
                _logger.LogInformation($"relayChanged() Entered. areaId: {areaId} deviceName: {deviceName} state: {swState} from {clientIP}");

                RelayDevice relay = relayDevices.Where(s => s.area == (Enums.ControlledAreas)areaId && s.deviceName == deviceName).FirstOrDefault();

                if (relay == null)
                {
                    return(NotFound());
                }

                if (relay.swState != swState)
                {
                    //relay.swState = swState;
                    //AreaEventType aet = swState > 0 ? AreaEventType.SwitchOn : AreaEventType.SwitchOff;
                    //AreaEvent evt = new AreaEvent(relay.area, deviceName, aet, relay.mcu.ipAddress, AreaEventStatus.Complete);
                    //relay.Events.Add(evt);
                    //EventLogger.logEvent(evt);
                    relay.setState(swState, true);
                }
                else
                {
                    _logger.LogInformation($"switchChanged() Done. State was unchanged.");
                }
                return(relay);
            }
        }
        public async Task <ActionResult <RelayDevice> > setRelay(int localId, int swState)
        {
            //var ipAddr = HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress;

            var clientIP = HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress.ToString();

            if (clientIP == "::1")
            {
                string[] parts = Environment.GetEnvironmentVariable("HOSTPORT").Split(':');
                clientIP = parts[0];
            }

            _logger.LogInformation($"setRelay() Entered. deviceId: {localId} State {swState} from {clientIP}");

            RelayDevice relay = relayDevices.Where(s => s.localDeviceId == localId).FirstOrDefault();

            if (relay == null)
            {
                return(NotFound());
            }
            else             //if (sw.swState != swState)
            {
                relay.setState(swState, true);
                //relay.swState = swState;
                //AreaEventType evtType = (swState > 0) ? AreaEventType.SwitchOn : AreaEventType.SwitchOff;
                //AreaEvent evt = new AreaEvent(relay.area, relay.deviceName, evtType, clientIP, AreaEventStatus.Complete);
                //relay.Events.Add(evt);
                //EventLogger.logEvent(evt);

                await relay.mcu.connection?.SendMessageAsync($"relaychanged:{relay.mcu.remoteDeviceId}:{relay.swState}");

                return(relay);
            }
        }