8000 [HVAC] Thermostat events implementation by hasty · Pull Request #39923 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[HVAC] Thermostat events implementation #39923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/thermostat/thermostat-common/thermostat.matter
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,7 @@ endpoint 1 {
ram attribute minSetpointDeadBand default = 0x19;
ram attribute controlSequenceOfOperation default = 0x04;
persist attribute systemMode default = 0x01;
ram attribute thermostatRunningMode default = 0;
callback attribute presetTypes;
ram attribute numberOfPresets default = 0;
ram attribute activePresetHandle;
Expand All @@ -2948,7 +2949,7 @@ endpoint 1 {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0x123;
ram attribute featureMap default = 0x323;
ram attribute clusterRevision default = 8;

handle command SetpointRaiseLower;
Expand Down
18 changes: 17 additions & 1 deletion examples/thermostat/thermostat-common/thermostat.zap
Original file line number Diff line number Diff line change
Expand Up @@ -5137,6 +5137,22 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "ThermostatRunningMode",
"code": 30,
"mfgCode": null,
"side": "server",
"type": "ThermostatRunningModeEnum",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "PresetTypes",
"code": 72,
Expand Down Expand Up @@ -5275,7 +5291,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x123",
"defaultValue": "0x323",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TARGET_SOURCES(
"${CLUSTER_DIR}/PresetStructWithOwnedMembers.h"
"${CLUSTER_DIR}/thermostat-delegate.h"
"${CLUSTER_DIR}/thermostat-server-atomic.cpp"
"${CLUSTER_DIR}/thermostat-server-events.cpp"
"${CLUSTER_DIR}/thermostat-server-presets.cpp"
"${CLUSTER_DIR}/thermostat-server.cpp"
"${CLUSTER_DIR}/thermostat-server.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ app_config_dependent_sources = [
"PresetStructWithOwnedMembers.h",
"thermostat-delegate.h",
"thermostat-server-atomic.cpp",
"thermostat-server-events.cpp",
"thermostat-server-presets.cpp",
"thermostat-server.cpp",
"thermostat-server.h",
Expand Down
153 changes: 153 additions & 0 deletions src/app/clusters/thermostat-server/thermostat-server-events.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
*
* Copyright (c) 2025 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "app/clusters/thermostat-server/thermostat-server.h"

#include "app/EventLogging.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;

void EmitSystemModeChangeEvent(EndpointId endpoint, Optional<SystemModeEnum> previousSystemMode, SystemModeEnum currentSystemMode)
{
Events::SystemModeChange::Type event;
EventNumber eventNumber;

event.previousSystemMode = previousSystemMode;
event.currentSystemMode = currentSystemMode;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit SystemModeChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitLocalTemperatureChangeEvent(EndpointId endpoint, DataModel::Nullable<int16_t> currentLocalTemperature)
{
Events::LocalTemperatureChange::Type event;
EventNumber eventNumber;

event.currentLocalTemperature = currentLocalTemperature;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit LocalTemperatureChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitOccupancyChangeEvent(EndpointId endpoint, Optional<chip::BitMask<OccupancyBitmap>> previousOccupancy,
chip::BitMask<OccupancyBitmap> currentOccupancy)
{
Events::OccupancyChange::Type event;
EventNumber eventNumber;

event.previousOccupancy = previousOccupancy;
event.currentOccupancy = currentOccupancy;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit OccupancyChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitSetpointChangeEvent(EndpointId endpoint, SystemModeEnum systemMode, Optional<chip::BitMask<OccupancyBitmap>> occupancy,
Optional<int16_t> previousSetpoint, int16_t currentSetpoint)
{
Events::SetpointChange::Type event;
EventNumber eventNumber;

event.systemMode = systemMode;
event.occupancy = occupancy;
event.previousSetpoint = previousSetpoint;
event.currentSetpoint = currentSetpoint;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit SetpointChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitRunningStateChangeEvent(EndpointId endpoint, Optional<chip::BitMask<RelayStateBitmap>> previousRunningState,
chip::BitMask<RelayStateBitmap> currentRunningState)
{
Events::RunningStateChange::Type event;
EventNumber eventNumber;

event.previousRunningState = previousRunningState;
event.currentRunningState = currentRunningState;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit RunningStateChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitRunningModeChangeEvent(EndpointId endpoint, Optional<ThermostatRunningModeEnum> previousRunningMode,
ThermostatRunningModeEnum currentRunningMode)
{
Events::RunningModeChange::Type event;
EventNumber eventNumber;

event.previousRunningMode = previousRunningMode;
event.currentRunningMode = currentRunningMode;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit RunningModeChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitActiveScheduleChangeEvent(EndpointId endpoint, Optional<DataModel::Nullable<chip::ByteSpan>> previousScheduleHandle,
DataModel::Nullable<chip::ByteSpan> currentScheduleHandle)
{
Events::ActiveScheduleChange::Type event;
EventNumber eventNumber;

event.previousScheduleHandle = previousScheduleHandle;
event.currentScheduleHandle = currentScheduleHandle;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit ActiveScheduleChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}

void EmitActivePresetChangeEvent(EndpointId endpoint, Optional<DataModel::Nullable<chip::ByteSpan>> previousPresetHandle,
DataModel::Nullable<chip::ByteSpan> currentPresetHandle)
{
Events::ActivePresetChange::Type event;
EventNumber eventNumber;

event.previousPresetHandle = previousPresetHandle;
event.currentPresetHandle = currentPresetHandle;

CHIP_ERROR err = LogEvent(event, endpoint, eventNumber);
if (CHIP_NO_ERROR != err)
{
ChipLogError(Zcl, "Failed to emit ActivePresetChange event: %" CHIP_ERROR_FORMAT, err.Format());
}
}
56 changes: 56 additions & 0 deletions src/app/clusters/thermostat-server/thermostat-server-events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
*
* Copyright (c) 2024 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/****************************************************************************
* @file
* @brief APIs for sending events from the Thermostat cluster.
*
*******************************************************************************
******************************************************************************/

#pragma once

void EmitSystemModeChangeEvent(chip::EndpointId endpoint,
chip::Optional<chip::app::Clusters::Thermostat::SystemModeEnum> previousSystemMode,
chip::app::Clusters::Thermostat::SystemModeEnum currentSystemMode);

void EmitLocalTemperatureChangeEvent(chip::EndpointId endpoint, chip::app::DataModel::Nullable<int16_t> currentLocalTemperature);

void EmitOccupancyChangeEvent(chip::EndpointId endpoint,
chip::Optional<chip::BitMask<chip::app::Clusters::Thermostat::OccupancyBitmap>> previousOccupancy,
chip::BitMask<chip::app::Clusters::Thermostat::OccupancyBitmap> currentOccupancy);

void EmitSetpointChangeEvent(chip::EndpointId endpoint, chip::app::Clusters::Thermostat::SystemModeEnum systemMode,
chip::Optional<chip::BitMask<chip::app::Clusters::Thermostat::OccupancyBitmap>> occupancy,
chip::Optional<int16_t> previousSetpoint, int16_t currentSetpoint);

void EmitRunningStateChangeEvent(
chip::EndpointId endpoint,
chip::Optional<chip::BitMask<chip::app::Clusters::Thermostat::RelayStateBitmap>> previousRunningState,
chip::BitMask<chip::app::Clusters::Thermostat::RelayStateBitmap> currentRunningState);

void EmitRunningModeChangeEvent(chip::EndpointId endpoint,
chip::Optional<chip::app::Clusters::Thermostat::ThermostatRunningModeEnum> previousRunningMode,
chip::app::Clusters::Thermostat::ThermostatRunningModeEnum currentRunningMode);

void EmitActiveScheduleChangeEvent(chip::EndpointId endpoint,
chip::Optional<chip::app::DataModel::Nullable<chip::ByteSpan>> previousScheduleHandle,
chip::app::DataModel::Nullable<chip::ByteSpan> currentScheduleHandle);

void EmitActivePresetChangeEvent(chip::EndpointId endpoint,
chip::Optional<chip::app::DataModel::Nullable<chip::ByteSpan>> previousPresetHandle,
chip::app::DataModel::Nullable<chip::ByteSpan> currentPresetHandle);
Loading
Loading
0