1 """Support for getting the state of a Thermoworks Smoke Thermometer.
3 Requires Smoke Gateway Wifi with an internet connection.
6 from __future__
import annotations
10 from requests
import RequestException
11 from requests.exceptions
import HTTPError
12 from stringcase
import camelcase, snakecase
13 import thermoworks_smoke
14 import voluptuous
as vol
17 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
25 CONF_MONITORED_CONDITIONS,
34 _LOGGER = logging.getLogger(__name__)
38 PROBE_1_MIN =
"probe1_min"
39 PROBE_1_MAX =
"probe1_max"
40 PROBE_2_MIN =
"probe2_min"
41 PROBE_2_MAX =
"probe2_max"
42 BATTERY_LEVEL =
"battery"
45 SERIAL_REGEX =
"^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$"
51 PROBE_1_MIN:
"Probe 1 Min",
52 PROBE_1_MAX:
"Probe 1 Max",
53 PROBE_2_MIN:
"Probe 2 Min",
54 PROBE_2_MAX:
"Probe 2 Max",
58 EXCLUDE_KEYS = [FIRMWARE]
60 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
62 vol.Required(CONF_EMAIL): cv.string,
63 vol.Required(CONF_PASSWORD): cv.string,
64 vol.Optional(CONF_MONITORED_CONDITIONS, default=[PROBE_1, PROBE_2]): vol.All(
65 cv.ensure_list, [vol.In(SENSOR_TYPES)]
67 vol.Optional(CONF_EXCLUDE, default=[]): vol.All(
68 cv.ensure_list, [cv.matches_regex(SERIAL_REGEX)]
77 add_entities: AddEntitiesCallback,
78 discovery_info: DiscoveryInfoType |
None =
None,
80 """Set up the thermoworks sensor."""
82 email = config[CONF_EMAIL]
83 password = config[CONF_PASSWORD]
84 monitored_variables = config[CONF_MONITORED_CONDITIONS]
85 excluded = config[CONF_EXCLUDE]
88 mgr = thermoworks_smoke.initialize_app(email, password,
True, excluded)
89 except HTTPError
as error:
90 msg = f
"{error.strerror}"
91 if "EMAIL_NOT_FOUND" in msg
or "INVALID_PASSWORD" in msg:
92 _LOGGER.error(
"Invalid email and password combination")
99 for serial
in mgr.serials()
100 for variable
in monitored_variables
107 """Implementation of a thermoworks smoke sensor."""
110 """Initialize the sensor."""
114 self.
_attr_name_attr_name = f
"{mgr.name(serial)} {SENSOR_TYPES[sensor_type]}"
121 """Set the units from the data."""
122 if PROBE_2
in self.
typetype:
128 """Get the monitored data from firebase."""
141 "time": values[
"time"],
142 "localtime": values[
"localtime"],
146 if self.
typetype
in (PROBE_1, PROBE_2):
147 for key, val
in values.items():
150 if (self.
typetype == PROBE_1
and key.find(PROBE_2) == -1)
or (
151 self.
typetype == PROBE_2
and key.find(PROBE_1) == -1
153 if key == BATTERY_LEVEL:
154 key = ATTR_BATTERY_LEVEL
157 key = snakecase(key.replace(self.
typetype,
""))
159 if key
and key
not in EXCLUDE_KEYS:
166 except (RequestException, ValueError, KeyError):
167 _LOGGER.warning(
"Could not update status for %s", self.
namename)
_attr_extra_state_attributes
def __init__(self, sensor_type, serial, mgr)
_attr_native_unit_of_measurement
str|UndefinedType|None name(self)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)