Skip to content

Commit

Permalink
Add support for LTNE (Local Temperature Not Exposed) feature in Therm… (
Browse files Browse the repository at this point in the history
#26686)

* Add support for LTNE (Local Temperature Not Exposed) feature in Thermostat Cluster

* Restyled by clang-format

* Tidy up code and use error-mapping function

* Restyled by clang-format

* Tidy up code and add some comments

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
huangzh142 and restyled-commits authored May 24, 2023
1 parent 4c4edab commit b6d82fb
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,7 @@ client cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/apps/app1/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/apps/app2/config.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
1 change: 1 addition & 0 deletions examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
95 changes: 92 additions & 3 deletions src/app/clusters/thermostat-server/thermostat-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@
#include <lib/core/CHIPEncoding.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::Thermostat;
using namespace chip::app::Clusters::Thermostat::Attributes;

using imcode = Protocols::InteractionModel::Status;

constexpr int16_t kDefaultAbsMinHeatSetpointLimit = 700; // 7C (44.5 F) is the default
constexpr int16_t kDefaultAbsMaxHeatSetpointLimit = 3000; // 30C (86 F) is the default
constexpr int16_t kDefaultMinHeatSetpointLimit = 700; // 7C (44.5 F) is the default
Expand Down Expand Up @@ -62,6 +66,90 @@ constexpr int8_t kDefaultDeadBand = 25; // 2.5C is the default

#define FEATURE_MAP_DEFAULT FEATURE_MAP_HEAT | FEATURE_MAP_COOL | FEATURE_MAP_AUTO

namespace {

class ThermostatAttrAccess : public AttributeAccessInterface
{
public:
ThermostatAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), Thermostat::Id) {}

CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override;
};

ThermostatAttrAccess gThermostatAttrAccess;

CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
VerifyOrDie(aPath.mClusterId == Thermostat::Id);

uint32_t ourFeatureMap;
bool localTemperatureNotExposedSupported = (FeatureMap::Get(aPath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS) &&
((ourFeatureMap & to_underlying(Feature::kLocalTemperatureNotExposed)) != 0);

switch (aPath.mAttributeId)
{
case LocalTemperature::Id:
if (localTemperatureNotExposedSupported)
{
return aEncoder.EncodeNull();
}
break;
case RemoteSensing::Id:
if (localTemperatureNotExposedSupported)
{
uint8_t valueRemoteSensing;
EmberAfStatus status = RemoteSensing::Get(aPath.mEndpointId, &valueRemoteSensing);
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
StatusIB statusIB(ToInteractionModelStatus(status));
return statusIB.ToChipError();
}
valueRemoteSensing &= 0xFE; // clear bit 1 (LocalTemperature RemoteSensing bit)
return aEncoder.Encode(valueRemoteSensing);
}
break;
default: // return CHIP_NO_ERROR and just read from the attribute store in default
break;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR ThermostatAttrAccess::Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder)
{
VerifyOrDie(aPath.mClusterId == Thermostat::Id);

uint32_t ourFeatureMap;
bool localTemperatureNotExposedSupported = (FeatureMap::Get(aPath.mEndpointId, &ourFeatureMap) == EMBER_ZCL_STATUS_SUCCESS) &&
((ourFeatureMap & to_underlying(Feature::kLocalTemperatureNotExposed)) != 0);

switch (aPath.mAttributeId)
{
case RemoteSensing::Id:
if (localTemperatureNotExposedSupported)
{
uint8_t valueRemoteSensing;
ReturnErrorOnFailure(aDecoder.Decode(valueRemoteSensing));
if (valueRemoteSensing & 0x01) // If setting bit 1 (LocalTemperature RemoteSensing bit)
{
return CHIP_IM_GLOBAL_STATUS(ConstraintError);
}

EmberAfStatus status = RemoteSensing::Set(aPath.mEndpointId, valueRemoteSensing);
StatusIB statusIB(ToInteractionModelStatus(status));
return statusIB.ToChipError();
}
break;
default: // return CHIP_NO_ERROR and just write to the attribute store in default
break;
}

return CHIP_NO_ERROR;
}

} // anonymous namespace

void emberAfThermostatClusterServerInitCallback(chip::EndpointId endpoint)
{
// TODO
Expand All @@ -78,8 +166,6 @@ void emberAfThermostatClusterServerInitCallback(chip::EndpointId endpoint)
// or should this just be the responsibility of the thermostat application?
}

using imcode = Protocols::InteractionModel::Status;

Protocols::InteractionModel::Status
MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttributePath & attributePath,
EmberAfAttributeType attributeType, uint16_t size, uint8_t * value)
Expand Down Expand Up @@ -754,4 +840,7 @@ bool emberAfThermostatClusterSetpointRaiseLowerCallback(app::CommandHandler * co
return true;
}

void MatterThermostatPluginServerInitCallback() {}
void MatterThermostatPluginServerInitCallback()
{
registerAttributeAccessOverride(&gThermostatAttrAccess);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
<field name="ScheduleConfiguration" mask="0x8"/>
<field name="Setback" mask="0x10"/>
<field name="AutoMode" mask="0x20"/>
<field name="LocalTemperatureNotExposed" mask="0x40"/>
</bitmap>

<bitmap name="DayOfWeek" type="BITMAP8">
Expand Down
1 change: 1 addition & 0 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -4341,6 +4341,7 @@ client cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

bitmap ModeForSequence : BITMAP8 {
Expand Down
1 change: 1 addition & 0 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6d82fb

Please sign in to comment.