Пример #1
0
        protected async Task HandleMessage(MqttApplicationMessageReceivedEventArgs message)
        {
            var payload = Encoding.UTF8.GetString(message.ApplicationMessage.Payload);

            _logger.LogInformation($"Topic {message.ApplicationMessage.Topic}. Message {payload}");

            var messageEvent = JsonSerializer.Deserialize <AqaraOccupancySensorEvent>(payload);

            if (messageEvent.Occupancy)
            {
                _logger.LogInformation($"Occupancy detected {DateTime.Now.ToString("s")}");
                if (_alertStatusProvider.ShouldRaiseAlert())
                {
                    _logger.LogInformation($"Notifying alert. Last fired alert '{_alertStatusProvider.GetLastFiredAlert():s}'");
                    _alertStatusProvider.RaiseAlert();
                    await _alertNotifier.Notify($"[JJ.Alert.Occupancy] {message.ApplicationMessage.Topic}", $"Occupancy was detected.<br />Payload: <pre>{payload}</pre>");

                    var location = message.ApplicationMessage.Topic.Split('/').LastOrDefault()
                                   ?? message.ApplicationMessage.Topic;

                    await _alertsStore.WriteMeasure(new Db.Entities.AlertMeasure
                    {
                        Location = location,
                        Reason   = "occupancy",
                        Value    = 1,
                        Time     = _alertStatusProvider.GetLastFiredAlert() ?? DateTimeOffset.UtcNow
                    });
                }
            }
            else
            {
                _logger.LogDebug($"No occupancy detected");
            }
        }
Пример #2
0
 /// <inheritdoc />
 public async Task SendAlert(string input, bool requireConfirmation, Icon icon)
 {
     var alert = new Alert()
     {
         Message           = input,
         NeedsConfirmation = requireConfirmation,
         Icon = icon
     };
     await _alertNotifier.Notify(alert);
 }
Пример #3
0
        public OccupancyAlertServiceBuilder WithAlertNotifySucceeded()
        {
            AlertNotifier.Notify(Arg.Any <string>(), Arg.Any <string>()).Returns(Task.CompletedTask);

            return(this);
        }