-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsensors.py
More file actions
102 lines (68 loc) · 2.22 KB
/
Copy pathsensors.py
File metadata and controls
102 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Defines the sensor classes.
Description
-----------
Defines the base and end user classes for various sensors.
- *Sensor* - The base sensor class.
- *TempSensor* - The temperature sensor class.
Libraries/Modules
-----------------
- *random* Standard Library (https://docs.python.org/3/library/random.html)
- Provides access to the *randint* function.
Notes
-----
- Comments are Sphinx (reStructuredText) compatible.
TODO
----
- None.
Author(s)
---------
- Created by John Woolsey on 05/27/2020.
- Modified by John Woolsey on 04/21/2023.
Copyright (c) 2020 Woolsey Workshop. All rights reserved.
Members
-------
"""
import random
class Sensor:
"""The sensor base class.
Defines the base class utilized by all sensors.
"""
def __init__(self, name: str) -> None:
"""The Sensor base class initializer.
:param name: The name of the sensor.
:type name: str
"""
self.name: str = name
"""The name of the sensor."""
self.value: int = random.randint(0, 50)
"""The value of the sensor."""
def __str__(self) -> str:
"""Retrieves the sensor's description.
:return: A description of the sensor.
:rtype: str
"""
return f"The {self.name} sensor has a value of {self.value}."
class TempSensor(Sensor):
"""The temperature sensor class.
Provides access to the connected temperature sensor.
Supported units are `"F"` (Fahrenheit), `"C"` (Celsius), and `"K"` (Kelvin).
"""
def __init__(self, name, unit="F") -> None:
"""The TempSensor class initializer.
:param name: The name of the temperature sensor.
:type name: str
:param unit: The unit of the temperature sensor with values of
`"F"`, `"C"`, or `"K"`; defaults to `"F"`.
:type unit: str
"""
super().__init__(name)
self.unit: str = unit
"""The temperature unit."""
def __str__(self) -> str:
"""Retrieves the temperature sensor's description.
:return: A description of the temperature sensor.
"""
return (
f"The {self.name} temperature sensor has a value of "
f"{self.value} degrees {self.unit}."
)