Skip to content

Commit 63385d1

Browse files
committed
🐛 Don't allow non-object-temp SensorTypes to init a ds18 sensor
1 parent 7374287 commit 63385d1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/components/ds18x20/controller.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ DS18X20Controller::~DS18X20Controller() { delete _DS18X20_model; }
4545
bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
4646
// Attempt to decode the incoming message into a Ds18x20Add message
4747
if (!_DS18X20_model->DecodeDS18x20Add(stream)) {
48-
WS_DEBUG_PRINTLN("ERROR: Unable to decode Ds18x20Add message");
48+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to decode Ds18x20Add message");
4949
return false;
5050
}
5151

5252
// If we receive no sensor types to configure, bail out
5353
if (_DS18X20_model->GetDS18x20AddMsg()->sensor_types_count == 0) {
54-
WS_DEBUG_PRINTLN("ERROR: No ds18x sensor types provided!");
54+
WS_DEBUG_PRINTLN("ERROR | DS18x20: No ds18x sensor types provided!");
5555
return false;
5656
}
5757

@@ -87,27 +87,30 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
8787
_DS18X20_model->GetDS18x20AddMsg()->sensor_types[i] ==
8888
wippersnapper_sensor_SensorType_SENSOR_TYPE_OBJECT_TEMPERATURE_FAHRENHEIT) {
8989
new_dsx_driver->is_read_temp_f = true;
90+
} else {
91+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unknown SensorType, failed to add sensor!");
92+
return false;
9093
}
9194
}
9295

9396
// Add the DS18X20Hardware object to the vector of hardware objects
9497
_DS18X20_pins.push_back(std::move(new_dsx_driver));
9598
} else {
9699
WS_DEBUG_PRINTLN(
97-
"ERROR: Unable to get ds18x sensor ID, ds18x sensor not initialized");
100+
"ERROR | DS18x20: Unable to get sensor ID!");
98101
}
99102

100103
// Encode and publish a Ds18x20Added message back to the broker
101104
unsigned long encode_start_time = millis();
102105
if (!_DS18X20_model->EncodeDS18x20Added(
103106
_DS18X20_model->GetDS18x20AddMsg()->onewire_pin, is_initialized)) {
104-
WS_DEBUG_PRINTLN("ERROR: Unable to encode Ds18x20Added message");
107+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to encode Ds18x20Added message!");
105108
return false;
106109
}
107110

108111
if (!WsV2.PublishSignal(wippersnapper_signal_DeviceToBroker_ds18x20_added_tag,
109112
_DS18X20_model->GetDS18x20AddedMsg())) {
110-
WS_DEBUG_PRINTLN("ERROR: Unable to publish Ds18x20Added message");
113+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to publish Ds18x20Added message!");
111114
return false;
112115
}
113116

@@ -129,7 +132,7 @@ bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
129132
WS_DEBUG_PRINT("Removing DS18X20 sensor...");
130133
// Attempt to decode the stream
131134
if (!_DS18X20_model->DecodeDS18x20Remove(stream)) {
132-
WS_DEBUG_PRINTLN("ERROR: Unable to decode Ds18x20Remove message");
135+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to decode Ds18x20Remove message");
133136
return false;
134137
}
135138
// Create a temp. instance of the Ds18x20Remove message
@@ -144,7 +147,7 @@ bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
144147
return true;
145148
}
146149
}
147-
WS_DEBUG_PRINT("Removed!");
150+
WS_DEBUG_PRINTLN("Removed!");
148151
return true;
149152
}
150153

@@ -182,7 +185,7 @@ void DS18X20Controller::update() {
182185
#endif
183186

184187
if (!temp_dsx_driver.ReadTemperatureC()) {
185-
WS_DEBUG_PRINTLN("ERROR: Unable to read temperature in Celsius");
188+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to read temperature in Celsius");
186189
continue;
187190
}
188191

@@ -228,7 +231,7 @@ void DS18X20Controller::update() {
228231

229232
// Encode the Ds18x20Event message
230233
if (!_DS18X20_model->EncodeDs18x20Event()) {
231-
WS_DEBUG_PRINTLN("ERROR: Failed to encode Ds18x20Event message");
234+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Failed to encode Ds18x20Event message");
232235
continue;
233236
}
234237

@@ -237,7 +240,7 @@ void DS18X20Controller::update() {
237240
if (!WsV2.PublishSignal(
238241
wippersnapper_signal_DeviceToBroker_ds18x20_event_tag,
239242
_DS18X20_model->GetDS18x20EventMsg())) {
240-
WS_DEBUG_PRINTLN("ERROR: Failed to publish Ds18x20Event message");
243+
WS_DEBUG_PRINTLN("ERROR | DS18x20: Failed to publish Ds18x20Event message");
241244
continue;
242245
}
243246
WS_DEBUG_PRINTLN("Published!");

0 commit comments

Comments
 (0)