Skip to content

Commit

Permalink
Add support for thermostat running mode attribute to all clusters app (
Browse files Browse the repository at this point in the history
…#18777)

- Add Thermostat running mode to the m5 stack UI as well
  • Loading branch information
nivi-apple authored May 27, 2022
1 parent 41a6381 commit e5fe58d
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3395,6 +3395,7 @@ server cluster Thermostat = 513 {
attribute access(write: manage) int8s minSetpointDeadBand = 25;
attribute access(write: manage) ThermostatControlSequence controlSequenceOfOperation = 27;
attribute access(write: manage) enum8 systemMode = 28;
readonly attribute enum8 thermostatRunningMode = 30;
readonly attribute enum8 startOfWeek = 32;
readonly attribute int8u numberOfWeeklyTransitions = 33;
readonly attribute int8u numberOfDailyTransitions = 34;
Expand Down Expand Up @@ -4393,10 +4394,11 @@ endpoint 1 {
ram attribute minSetpointDeadBand default = 0x19;
ram attribute controlSequenceOfOperation default = 0x04;
ram attribute systemMode default = 0x01;
ram attribute thermostatRunningMode;
ram attribute startOfWeek;
ram attribute numberOfWeeklyTransitions default = 7;
ram attribute numberOfDailyTransitions default = 4;
ram attribute featureMap default = 0x000b;
ram attribute featureMap default = 0x002b;
ram attribute clusterRevision default = 5;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15124,6 +15124,22 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "ThermostatRunningMode",
"code": 30,
"mfgCode": null,
"side": "server",
"type": "enum8",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x00",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "StartOfWeek",
"code": 32,
Expand Down Expand Up @@ -15198,7 +15214,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x000b",
"defaultValue": "0x002b",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
Expand Down
110 changes: 101 additions & 9 deletions examples/all-clusters-app/esp32/main/DeviceWithDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "DeviceWithDisplay.h"
#include <app-common/zap-generated/cluster-enums.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>

#if CONFIG_HAVE_DISPLAY
Expand Down Expand Up @@ -134,6 +135,39 @@ class EditAttributeListModel : public TouchesMatterStackModel
return i == 0 ? "+" : "-";
}

// We support system modes - Off, Auto, Heat and Cool currently. This API returns true for all these modes,
// false otherwise.
bool isValidThermostatSystemMode(uint8_t systemMode)
{
chip::app::Clusters::Thermostat::ThermostatSystemMode mode =
static_cast<chip::app::Clusters::Thermostat::ThermostatSystemMode>(systemMode);
switch (mode)
{
case chip::app::Clusters::Thermostat::ThermostatSystemMode::kOff:
case chip::app::Clusters::Thermostat::ThermostatSystemMode::kAuto:
case chip::app::Clusters::Thermostat::ThermostatSystemMode::kCool:
case chip::app::Clusters::Thermostat::ThermostatSystemMode::kHeat:
return true;
default:
return false;
}
}

bool isValidThermostatRunningMode(uint8_t runningMode)
{
chip::app::Clusters::Thermostat::ThermostatRunningMode mode =
static_cast<chip::app::Clusters::Thermostat::ThermostatRunningMode>(runningMode);
switch (mode)
{
case chip::app::Clusters::Thermostat::ThermostatRunningMode::kOff:
case chip::app::Clusters::Thermostat::ThermostatRunningMode::kCool:
case chip::app::Clusters::Thermostat::ThermostatRunningMode::kHeat:
return true;
default:
return false;
}
}

void DoAction(int i) override
{
auto & attribute = this->attribute();
Expand Down Expand Up @@ -182,20 +216,74 @@ class EditAttributeListModel : public TouchesMatterStackModel
ESP_LOGI(TAG, "Humidity changed to : %d", n);
app::Clusters::RelativeHumidityMeasurement::Attributes::MeasuredValue::Set(1, static_cast<int16_t>(n * 100));
}
else if (name == "OccupiedCoolingSetpoint")
else if (name == "CoolSetpoint")
{
ESP_LOGI(TAG, "OccupiedCoolingSetpoint changed to : %d", n);
// update the occupied cooling setpoint for hardcoded endpoint 1
ESP_LOGI(TAG, "Occupied Cooling Setpoint changed to : %d", n);
app::Clusters::Thermostat::Attributes::OccupiedCoolingSetpoint::Set(1, static_cast<int16_t>(n * 100));
}
else if (name == "OccupiedHeatingSetpoint")
else if (name == "HeatSetpoint")
{
ESP_LOGI(TAG, "OccupiedHeatingSetpoint changed to : %d", n);
// update the occupied heating setpoint for hardcoded endpoint 1
ESP_LOGI(TAG, "Occupied Heating Setpoint changed to : %d", n);
app::Clusters::Thermostat::Attributes::OccupiedHeatingSetpoint::Set(1, static_cast<int16_t>(n * 100));
}
else if (name == "SystemMode")
{
ESP_LOGI(TAG, "SystemMode changed to : %d", n);
app::Clusters::Thermostat::Attributes::OccupiedHeatingSetpoint::Set(1, n);
// System modes - Off, Auto, Cool and Heat are currently supported.
uint8_t mode = n;
// Update the system mode here for hardcoded endpoint 1
if (isValidThermostatSystemMode(mode))
{
ESP_LOGI(TAG, "System Mode changed to : %d", mode);
app::Clusters::Thermostat::Attributes::SystemMode::Set(1, static_cast<uint8_t>(mode));
// If system mode is auto set running mode to off otherwise set it to what the system mode is set to
if (mode == static_cast<uint8_t>(chip::app::Clusters::Thermostat::ThermostatSystemMode::kAuto))
{
app::Clusters::Thermostat::Attributes::ThermostatRunningMode::Set(
1, static_cast<uint8_t>(chip::app::Clusters::Thermostat::ThermostatRunningMode::kOff));
}
else
{
if (isValidThermostatRunningMode(mode))
{
ESP_LOGI(TAG, "Running Mode changed to : %d", mode);
app::Clusters::Thermostat::Attributes::ThermostatRunningMode::Set(1, static_cast<uint8_t>(mode));
}
else
{
ESP_LOGI(TAG, "Running Mode %d is not valid", mode);
}
}
}
else
{
ESP_LOGI(TAG, "System Mode %d is not valid", mode);
}
}
else if (name == "RunningMode")
{
// Get the system mode
uint8_t systemMode = static_cast<uint8_t>(chip::app::Clusters::Thermostat::ThermostatRunningMode::kOff);
app::Clusters::Thermostat::Attributes::SystemMode::Get(1, static_cast<uint8_t *>(&systemMode));
if (systemMode != static_cast<uint8_t>(chip::app::Clusters::Thermostat::ThermostatSystemMode::kAuto))
{
ESP_LOGI(TAG, "Running mode can be changed only for system mode auto. Current system mode %d", systemMode);
}
else
{
uint8_t mode = n;
// update the running mode here for hardcoded endpoint 1
if (isValidThermostatRunningMode(mode))
{
ESP_LOGI(TAG, "Running Mode changed to : %d", mode);
app::Clusters::Thermostat::Attributes::ThermostatRunningMode::Set(1, static_cast<uint8_t>(mode));
}
else
{
ESP_LOGI(TAG, "Running Mode %d is not valid", mode);
}
}
}
else if (name == "Current Lift")
{
Expand Down Expand Up @@ -543,11 +631,15 @@ void SetupPretendDevices()
app::Clusters::TemperatureMeasurement::Attributes::MeasuredValue::Set(1, static_cast<int16_t>(21 * 100));
app::Clusters::Thermostat::Attributes::LocalTemperature::Set(1, static_cast<int16_t>(21 * 100));
AddAttribute("SystemMode", "4");
app::Clusters::Thermostat::Attributes::SystemMode::Set(1, 4);
AddAttribute("OccupiedCoolingSetpoint", "19");
app::Clusters::Thermostat::Attributes::SystemMode::Set(
1, static_cast<uint8_t>(chip::app::Clusters::Thermostat::ThermostatSystemMode::kHeat));
AddAttribute("CoolSetpoint", "19");
app::Clusters::Thermostat::Attributes::OccupiedCoolingSetpoint::Set(1, static_cast<int16_t>(19 * 100));
AddAttribute("OccupiedHeatingSetpoint", "25");
AddAttribute("HeatSetpoint", "25");
app::Clusters::Thermostat::Attributes::OccupiedHeatingSetpoint::Set(1, static_cast<int16_t>(25 * 100));
AddAttribute("RunningMode", "4");
app::Clusters::Thermostat::Attributes::ThermostatRunningMode::Set(
1, static_cast<uint8_t>(chip::app::Clusters::Thermostat::ThermostatRunningMode::kHeat));

AddDevice("Humidity Sensor");
AddEndpoint("External");
Expand Down
Loading

0 comments on commit e5fe58d

Please sign in to comment.