Skip to content

Commit 7c2e796

Browse files
committed
Adds active hold support
1 parent 96bc6b3 commit 7c2e796

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

src/HomeAutio.Mqtt.Ecobee/EcobeeMqttService.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text;
45
using System.Threading;
@@ -111,7 +112,8 @@ protected override async void Mqtt_MqttMsgPublishReceived(MqttApplicationMessage
111112
// Desired Cool - desiredCool/set
112113
var request = new ThermostatUpdateRequest
113114
{
114-
Selection = new Selection {
115+
Selection = new Selection
116+
{
115117
SelectionType = "thermostats",
116118
SelectionMatch = thermostatId
117119
}
@@ -314,9 +316,10 @@ private async Task RefreshThermostatAsync(RevisionStatus revisionStatus)
314316
SelectionType = "thermostats",
315317
SelectionMatch = revisionStatus.ThermostatIdentifier,
316318
IncludeEquipmentStatus = true,
317-
IncludeSettings = true,
319+
IncludeEvents = true,
318320
IncludeRuntime = true,
319321
IncludeSensors = true,
322+
IncludeSettings = true,
320323
IncludeWeather = true
321324
}
322325
};
@@ -403,6 +406,21 @@ private async Task UpdateState(Thermostat thermostat)
403406
}
404407
}
405408

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+
406424
if (_thermostatStatus.ContainsKey(thermostat.Identifier))
407425
{
408426
// Publish updates
@@ -434,6 +452,21 @@ await MqttClient.PublishAsync(new MqttApplicationMessageBuilder()
434452
}
435453
}
436454

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+
437470
// Publish everything for new sensors, new capabilities, and changes in existing ability values
438471
foreach (var sensor in thermostatStatus.Sensors)
439472
{
@@ -497,6 +530,21 @@ await MqttClient.PublishAsync(new MqttApplicationMessageBuilder()
497530
.ConfigureAwait(false);
498531
}
499532

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+
500548
foreach (var sensor in thermostatStatus.Sensors)
501549
{
502550
foreach (var sensorCapability in sensor.Value)

src/HomeAutio.Mqtt.Ecobee/ThermostatStatus.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ public ThermostatStatus()
1616

1717
Status = new Dictionary<string, string>();
1818

19+
ActiveHold = new Dictionary<string, string>
20+
{
21+
{ "running", "false" },
22+
{ "startTime", null },
23+
{ "endTime", null },
24+
{ "coldHoldTemp", null },
25+
{ "heatHoldTemp", null },
26+
{ "fan", null },
27+
{ "fanMinOnTime", null },
28+
{ "vent", null },
29+
{ "ventilatorMinOnTime", null }
30+
};
31+
1932
EquipmentStatus = new Dictionary<string, string>
2033
{
2134
{ "heatPump", "off" },
@@ -36,6 +49,16 @@ public ThermostatStatus()
3649
};
3750
}
3851

52+
/// <summary>
53+
/// Running event.
54+
/// </summary>
55+
public IDictionary<string, string> ActiveHold { get; }
56+
57+
/// <summary>
58+
/// Equipment statuses.
59+
/// </summary>
60+
public IDictionary<string, string> EquipmentStatus { get; }
61+
3962
/// <summary>
4063
/// Sensor statuses.
4164
/// </summary>
@@ -45,10 +68,5 @@ public ThermostatStatus()
4568
/// Thermostat statuses.
4669
/// </summary>
4770
public IDictionary<string, string> Status { get; }
48-
49-
/// <summary>
50-
/// Equipment statuses.
51-
/// </summary>
52-
public IDictionary<string, string> EquipmentStatus { get; }
5371
}
5472
}

0 commit comments

Comments
 (0)