Обновление статуса переехало в отдельный класс, в реакции на сообщение только известный набор статусов возвращаем

This commit is contained in:
ftc
2024-01-20 19:14:35 +03:00
parent 9a005df9c7
commit 15bf517434
4 changed files with 97 additions and 10 deletions
+9 -10
View File
@@ -10,6 +10,7 @@ using Telegram.Bot.Args;
using Telegram.Bot.Types.ReplyMarkups;
using ZaoBot.Config;
using ZaoBot.OpenHab;
using ZaoBot.Problems;
namespace ZaoBot
{
@@ -22,13 +23,18 @@ namespace ZaoBot
HttpClient http = new HttpClient();
OpenHabClient openhab;
IServiceProvider services;
StatusManager statusManager;
public StatusMenuUserState(IServiceProvider services, ITelegramBotClient botClient, IConfig config, OpenHabClient openhab)
public StatusMenuUserState(IServiceProvider services, ITelegramBotClient botClient,
IConfig config,
OpenHabClient openhab,
StatusManager statusManager)
{
this.botClient = botClient;
this.config = config.Data;
this.openhab = openhab;
this.services = services;
this.statusManager = statusManager;
}
public async Task<IUserState> ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e)
@@ -37,16 +43,9 @@ namespace ZaoBot
if (previous != this)
{
response = "Возможные проблемы:\n";
var items = await openhab.GetItems();
foreach (var item in items)
foreach (var item in statusManager.StatusItems)
{
if (!item.name.StartsWith("Problem_")) continue;
response += item.label + ": ";
var state = await openhab.GetItemState(item.name);
if (state.state == "OFF") response += "OK";
else if (state.state == "ON") response += "PROBLEM!";
else response += "UNKNOWN";
response += "\n";
response += item.label + ": " + item.status + "\n";
}
}
else if (e.Message.Text == CMD_BACK)