1 """Support for getting temperature from TEMPer devices."""
3 from __future__
import annotations
7 from temperusb.temper
import TemperHandler
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
25 _LOGGER = logging.getLogger(__name__)
29 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
31 vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): vol.Coerce(str),
32 vol.Optional(CONF_SCALE, default=1): vol.Coerce(float),
33 vol.Optional(CONF_OFFSET, default=0): vol.Coerce(float),
37 TEMPER_SENSORS: list[TemperSensor] = []
41 """Scan the Temper devices from temperusb."""
42 return TemperHandler().get_devices()
48 add_entities: AddEntitiesCallback,
49 discovery_info: DiscoveryInfoType |
None =
None,
51 """Set up the Temper sensors."""
52 prefix = name = config[CONF_NAME]
53 scaling = {
"scale": config.get(CONF_SCALE),
"offset": config.get(CONF_OFFSET)}
56 for idx, dev
in enumerate(temper_devices):
58 name = f
"{prefix}_{idx!s}"
64 """Re-scan for underlying Temper sensors and assign them to our devices.
66 This assumes the same sensor devices are present in the same order.
69 for sensor, device
in zip(TEMPER_SENSORS, temper_devices, strict=
False):
70 sensor.set_temper_device(device)
74 """Representation of a Temper temperature sensor."""
76 _attr_device_class = SensorDeviceClass.TEMPERATURE
77 _attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
79 def __init__(self, temper_device, name, scaling):
80 """Initialize the sensor."""
81 self.
scalescale = scaling[
"scale"]
82 self.
offsetoffset = scaling[
"offset"]
88 """Assign the underlying device for this sensor."""
95 """Retrieve latest state."""
101 "Failed to get temperature. The device address may"
102 "have changed. Attempting to reset device"
def __init__(self, temper_device, name, scaling)
def set_temper_device(self, temper_device)
def add_entities(account, async_add_entities, tracked)
float|None get_temperature(MadVRCoordinator coordinator, str key)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)