|
1 | | -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Linq; |
3 | 4 | using System.Text; |
4 | 5 | using System.Threading; |
@@ -111,7 +112,8 @@ protected override async void Mqtt_MqttMsgPublishReceived(MqttApplicationMessage |
111 | 112 | // Desired Cool - desiredCool/set |
112 | 113 | var request = new ThermostatUpdateRequest |
113 | 114 | { |
114 | | - Selection = new Selection { |
| 115 | + Selection = new Selection |
| 116 | + { |
115 | 117 | SelectionType = "thermostats", |
116 | 118 | SelectionMatch = thermostatId |
117 | 119 | } |
@@ -314,9 +316,10 @@ private async Task RefreshThermostatAsync(RevisionStatus revisionStatus) |
314 | 316 | SelectionType = "thermostats", |
315 | 317 | SelectionMatch = revisionStatus.ThermostatIdentifier, |
316 | 318 | IncludeEquipmentStatus = true, |
317 | | - IncludeSettings = true, |
| 319 | + IncludeEvents = true, |
318 | 320 | IncludeRuntime = true, |
319 | 321 | IncludeSensors = true, |
| 322 | + IncludeSettings = true, |
320 | 323 | IncludeWeather = true |
321 | 324 | } |
322 | 325 | }; |
@@ -403,6 +406,21 @@ private async Task UpdateState(Thermostat thermostat) |
403 | 406 | } |
404 | 407 | } |
405 | 408 |
|
| 409 | + // Hold |
| 410 | + var holdEvent = thermostat.Events.FirstOrDefault(x => x.Type == "hold"); |
| 411 | + if (holdEvent != null && holdEvent.Running) |
| 412 | + { |
| 413 | + thermostatStatus.ActiveHold["running"] = holdEvent.Running.ToString(); |
| 414 | + thermostatStatus.ActiveHold["startTime"] = DateTime.Parse($"{holdEvent.StartDate} {holdEvent.StartTime}").ToString(); |
| 415 | + thermostatStatus.ActiveHold["endTime"] = DateTime.Parse($"{holdEvent.EndDate} {holdEvent.EndTime}").ToString(); |
| 416 | + thermostatStatus.ActiveHold["coldHoldTemp"] = (holdEvent.CoolHoldTemp / 10m).ToString(); |
| 417 | + thermostatStatus.ActiveHold["heatHoldTemp"] = (holdEvent.HeatHoldTemp / 10m).ToString(); |
| 418 | + thermostatStatus.ActiveHold["fan"] = holdEvent.Fan; |
| 419 | + thermostatStatus.ActiveHold["fanMinOnTime"] = holdEvent.FanMinOnTime.ToString(); |
| 420 | + thermostatStatus.ActiveHold["vent"] = holdEvent.Vent; |
| 421 | + thermostatStatus.ActiveHold["ventilatorMinOnTime"] = holdEvent.VentilatorMinOnTime.ToString(); |
| 422 | + } |
| 423 | + |
406 | 424 | if (_thermostatStatus.ContainsKey(thermostat.Identifier)) |
407 | 425 | { |
408 | 426 | // Publish updates |
@@ -434,6 +452,21 @@ await MqttClient.PublishAsync(new MqttApplicationMessageBuilder() |
434 | 452 | } |
435 | 453 | } |
436 | 454 |
|
| 455 | + // Hold status |
| 456 | + foreach (var holdStatus in thermostatStatus.ActiveHold) |
| 457 | + { |
| 458 | + if (holdStatus.Value != _thermostatStatus[thermostat.Identifier].ActiveHold[holdStatus.Key]) |
| 459 | + { |
| 460 | + await MqttClient.PublishAsync(new MqttApplicationMessageBuilder() |
| 461 | + .WithTopic($"{TopicRoot}/{thermostat.Identifier}/hold/{holdStatus.Key}") |
| 462 | + .WithPayload(holdStatus.Value) |
| 463 | + .WithAtLeastOnceQoS() |
| 464 | + .WithRetainFlag() |
| 465 | + .Build()) |
| 466 | + .ConfigureAwait(false); |
| 467 | + } |
| 468 | + } |
| 469 | + |
437 | 470 | // Publish everything for new sensors, new capabilities, and changes in existing ability values |
438 | 471 | foreach (var sensor in thermostatStatus.Sensors) |
439 | 472 | { |
@@ -497,6 +530,21 @@ await MqttClient.PublishAsync(new MqttApplicationMessageBuilder() |
497 | 530 | .ConfigureAwait(false); |
498 | 531 | } |
499 | 532 |
|
| 533 | + // Hold status |
| 534 | + foreach (var holdStatus in thermostatStatus.ActiveHold) |
| 535 | + { |
| 536 | + if (holdStatus.Value != _thermostatStatus[thermostat.Identifier].ActiveHold[holdStatus.Key]) |
| 537 | + { |
| 538 | + await MqttClient.PublishAsync(new MqttApplicationMessageBuilder() |
| 539 | + .WithTopic($"{TopicRoot}/{thermostat.Identifier}/hold/{holdStatus.Key}") |
| 540 | + .WithPayload(holdStatus.Value) |
| 541 | + .WithAtLeastOnceQoS() |
| 542 | + .WithRetainFlag() |
| 543 | + .Build()) |
| 544 | + .ConfigureAwait(false); |
| 545 | + } |
| 546 | + } |
| 547 | + |
500 | 548 | foreach (var sensor in thermostatStatus.Sensors) |
501 | 549 | { |
502 | 550 | foreach (var sensorCapability in sensor.Value) |
|
0 commit comments