1 """Sensor platform integration for ADC ports of Numato USB GPIO expanders."""
3 from __future__
import annotations
7 from numato_gpio
import NumatoGpioError
25 _LOGGER = logging.getLogger(__name__)
31 add_entities: AddEntitiesCallback,
32 discovery_info: DiscoveryInfoType |
None =
None,
34 """Set up the configured Numato USB GPIO ADC sensor ports."""
35 if discovery_info
is None:
38 api = hass.data[DOMAIN][DATA_API]
40 devices = hass.data[DOMAIN][CONF_DEVICES]
41 for device
in [d
for d
in devices
if CONF_SENSORS
in d]:
42 device_id = device[CONF_ID]
43 ports = device[CONF_SENSORS][CONF_PORTS]
44 for port, adc_def
in ports.items():
46 api.setup_input(device_id, port)
47 except NumatoGpioError
as err:
49 "Failed to initialize sensor '%s' on Numato device %s port %s: %s",
61 adc_def[CONF_SRC_RANGE],
62 adc_def[CONF_DST_RANGE],
63 adc_def[CONF_DST_UNIT],
71 """Represents an ADC port of a Numato USB GPIO expander."""
73 _attr_icon =
"mdi:gauge"
75 def __init__(self, name, device_id, port, src_range, dst_range, dst_unit, api):
76 """Initialize the sensor."""
86 """Get the latest data and updates the state."""
91 except NumatoGpioError
as err:
94 "Failed to update Numato device %s ADC-port %s: %s",
108 adc_val_rel = val - self.
_src_range_src_range[0]
111 return self.
_dst_range_dst_range[0] + ratio * dst_len
def _clamp_to_source_range(self, val)
_attr_native_unit_of_measurement
def _linear_scale_to_dest_range(self, val)
def __init__(self, name, device_id, port, src_range, dst_range, dst_unit, api)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)