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
…ostat Cluster
  • Loading branch information
huangzh142 committed May 19, 2023
1 parent e75e729 commit ba43565
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3208,6 +3208,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

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

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

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

struct ThermostatScheduleTransition {
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 @@ -2481,6 +2481,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

struct ThermostatScheduleTransition {
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 @@ -2442,6 +2442,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

struct ThermostatScheduleTransition {
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 @@ -1681,6 +1681,7 @@ server cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

struct ThermostatScheduleTransition {
Expand Down
92 changes: 89 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 All @@ -59,9 +63,90 @@ constexpr int8_t kDefaultDeadBand = 25; // 2.5C is the default
#define FEATURE_MAP_SCH 0x08
#define FEATURE_MAP_SB 0x10
#define FEATURE_MAP_AUTO 0x20
#define FEATURE_MAP_LTNE 0x40

#define FEATURE_MAP_DEFAULT FEATURE_MAP_HEAT | FEATURE_MAP_COOL | FEATURE_MAP_AUTO

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);

bool LTNESupported = false;
uint32_t OurFeatureMap;

if (FeatureMap::Get(aPath.mEndpointId, &OurFeatureMap) == EMBER_ZCL_STATUS_SUCCESS && OurFeatureMap & 1 << 6) // Bit 6 is LTNE supported
LTNESupported = true;

switch (aPath.mAttributeId)
{
case LocalTemperature::Id: {
if(LTNESupported)
return aEncoder.EncodeNull();
break;
}
case RemoteSensing::Id: {
if(LTNESupported)
{
uint8_t valueRemoteSensing;
VerifyOrReturnValue(RemoteSensing::Get(aPath.mEndpointId, &valueRemoteSensing) == EMBER_ZCL_STATUS_SUCCESS, CHIP_NO_ERROR);
valueRemoteSensing &= 0xFE; // clear bit 1 (LocalTemperature RemoteSensing bit)
return aEncoder.Encode(valueRemoteSensing);
}
break;
}
default:
break;
}

return CHIP_NO_ERROR;
}

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

bool LTNESupported = false;
uint32_t OurFeatureMap;

if (FeatureMap::Get(aPath.mEndpointId, &OurFeatureMap) == EMBER_ZCL_STATUS_SUCCESS && OurFeatureMap & 1 << 6) // Bit 6 is LTNE supported
LTNESupported = true;

switch (aPath.mAttributeId)
{
case RemoteSensing::Id: {
if(LTNESupported)
{
uint8_t valueRemoteSensing;
ReturnErrorOnFailure(aDecoder.Decode(valueRemoteSensing));
if(valueRemoteSensing & 0x01) // If setting bit 1 (LocalTemperature RemoteSensing bit)
{
return StatusIB(imcode::ConstraintError).ToChipError();
}
else
{
RemoteSensing::Set(aPath.mEndpointId, valueRemoteSensing);
}
}
break;
}
default:
break;
}

return CHIP_NO_ERROR;
}

void emberAfThermostatClusterServerInitCallback(chip::EndpointId endpoint)
{
// TODO
Expand All @@ -78,8 +163,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 +837,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 @@ -4318,6 +4318,7 @@ client cluster Thermostat = 513 {
kScheduleConfiguration = 0x8;
kSetback = 0x10;
kAutoMode = 0x20;
kLocalTemperatureNotExposed = 0x40;
}

struct ThermostatScheduleTransition {
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 ba43565

Please sign in to comment.