aquarium_control/sensors/ds18b20_error.rs
1/* Copyright 2025 Uwe Martin
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8*/
9
10use thiserror::Error;
11
12#[derive(Error, Debug, Clone)]
13pub enum Ds18b20Error {
14 /// Indicates that a DS18B20 sensor with the specified ID could not be found on the 1-Wire bus.
15 #[error("[{0}] DS18B20 sensor with ID {1} not found.")]
16 SensorIdNotFound(String, String),
17
18 /// Represents a failure to read the entire content of the sensor's device file into a string.
19 #[error("[{0}] Failed to read content from the device file.")]
20 ReadToStringFailure(String),
21
22 /// Occurs when the sensor's device file does not contain the expected two lines of data.
23 #[error("[{0}] Device file contains insufficient lines (expected at least 2).")]
24 InsufficientLinesInFile(String),
25
26 /// The first line from the sensor file must end with ' YES' to confirm a successful CRC check.
27 /// This error means the check failed, indicating a data transmission error.
28 #[error("[{0}] The first line of the device file does not end with ' YES', indicating a CRC error or incomplete reading.")]
29 Line0NotEndingWithYes(String),
30
31 /// The second line of the sensor file is expected to contain a temperature value prefixed with 't='.
32 /// This error indicates the prefix was not found.
33 #[error("[{0}] Temperature entry (t=) not found in the second line of the device file.")]
34 TemperatureEntryNotFound(String),
35
36 /// A generic error for cases that do not fit any other specific error variant.
37 #[error("[{0}] An unidentified error occurred.")]
38 UnidentifiedError(String),
39
40 /// The temperature value found in the sensor file could not be successfully parsed into a numeric type.
41 #[error("[{0}] Failed to parse temperature value as a floating-point number.")]
42 TemperatureParseError(String),
43
44 /// The parsed temperature value is outside the plausible range for an aquarium,
45 /// suggesting a sensor malfunction or reading error.
46 #[error("[{0}] Temperature value read from sensor is outside the expected range.")]
47 TemperatureOutOfRange(String),
48
49 /// System driver base path prefix is empty.
50 #[error("[{0}] System driver base path prefix is empty.")]
51 SystemDriverBasePathEmpty(String),
52
53 /// System driver sensor path prefix is empty.
54 #[error("[{0}] System driver sensor path prefix is empty.")]
55 SystemDriverSensorPathEmpty(String),
56
57 /// System driver file name is empty.
58 #[error("[{0}] System driver file name is empty.")]
59 SystemDriverFileNameEmpty(String),
60
61 /// No water temperature sensor ID nor ambient temperature sensor ID provided.
62 #[error("[{0}] No water temperature sensor ID nor ambient temperature sensor ID provided!")]
63 NoSensorIdProvided(String),
64
65 /// Ambient and water temperature sensor IDs are identical.
66 #[error("Ambient and water temperature sensor IDs are identical.")]
67 SensorIdsIdentical(String),
68}