@@ -23,43 +23,41 @@ class MatterTemperatureSensor : public MatterEndPoint {
2323public:
2424 MatterTemperatureSensor ();
2525 ~MatterTemperatureSensor ();
26- // begin Matter Temperature Sensor endpoint
27- virtual bool begin (int16_t _rawTemperature = 0 );
28- bool begin (double temperatureCelcius) {
29- int16_t rawValue = static_cast <int16_t >(temperatureCelcius * 100 .0f );
30- return begin (rawValue);
26+ // begin Matter Temperature Sensor endpoint with initial float temperature
27+ bool begin (double temperature) {
28+ return setTemperature (temperature);
3129 }
3230 // this will stop processing Temperature Sensor Matter events
3331 void end ();
3432
3533 // set the reported raw temperature
36- bool setRawTemperature ( int16_t _rawTemperature);
37- bool setTemperatureCelsius ( double temperatureCelcius) {
38- int16_t rawValue = static_cast <int16_t >(temperatureCelcius * 100 .0f );
34+ bool setTemperature ( double temperature) {
35+ // stores up to 1/100th of a degree precision
36+ int16_t rawValue = static_cast <int16_t >(temperature * 100 .0f );
3937 return setRawTemperature (rawValue);
4038 }
41- // returns the reported raw temperature (in 1/100th of a degree)
42- int16_t getRawTemperature () {
43- return rawTemperature;
44- }
45- // returns the reported temperature in Celcius
46- double getTemperatureCelsius () {
39+ // returns the reported float temperature with 1/100th of a degree precision
40+ double getTemperature () {
4741 return (double )rawTemperature / 100.0 ;
4842 }
49- // sets the reported temperature in Celcius
50- void operator =(double temperatureCelcius) {
51- int16_t rawValue = static_cast <int16_t >(temperatureCelcius * 100 .0f );
52- setRawTemperature (rawValue);
43+ // double conversion operator
44+ void operator =(double temperature) {
45+ setTemperature (temperature);
5346 }
47+ // double conversion operator
5448 operator double () {
55- return (double ) getTemperatureCelsius ();
49+ return (double ) getTemperature ();
5650 }
5751
5852 // this function is called by Matter internal event processor. It could be overwritten by the application, if necessary.
5953 bool attributeChangeCB (uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val);
6054
6155protected:
6256 bool started = false ;
63- int16_t rawTemperature = 0 ; // default initial reported temperature
57+ // implementation keeps temperature in 1/100th of a degree, any temperature unit
58+ int16_t rawTemperature = 0 ;
59+ // internal function to set the raw temperature value (Matter Cluster)
60+ bool setRawTemperature (int16_t _rawTemperature);
61+ bool begin (int16_t _rawTemperature);
6462};
6563#endif /* CONFIG_ESP_MATTER_ENABLE_DATA_MODEL */
0 commit comments