1 """Sensor platform for IronOS integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from enum
import StrEnum
9 from pynecil
import LiveDataResponse, OperatingMode, PowerSource
15 SensorEntityDescription,
20 UnitOfElectricPotential,
29 from .
import IronOSConfigEntry
30 from .const
import OHM
31 from .entity
import IronOSBaseEntity
35 """Pinecil Sensors."""
37 LIVE_TEMP =
"live_temperature"
38 SETPOINT_TEMP =
"setpoint_temperature"
39 DC_VOLTAGE =
"voltage"
40 HANDLETEMP =
"handle_temperature"
41 PWMLEVEL =
"power_pwm_level"
42 POWER_SRC =
"power_source"
43 TIP_RESISTANCE =
"tip_resistance"
45 MOVEMENT_TIME =
"movement_time"
46 MAX_TIP_TEMP_ABILITY =
"max_tip_temp_ability"
47 TIP_VOLTAGE =
"tip_voltage"
48 HALL_SENSOR =
"hall_sensor"
49 OPERATING_MODE =
"operating_mode"
50 ESTIMATED_POWER =
"estimated_power"
53 @dataclass(frozen=True, kw_only=True)
55 """IronOS sensor entity descriptions."""
57 value_fn: Callable[[LiveDataResponse], StateType]
60 PINECIL_SENSOR_DESCRIPTIONS: tuple[IronOSSensorEntityDescription, ...] = (
62 key=PinecilSensor.LIVE_TEMP,
63 translation_key=PinecilSensor.LIVE_TEMP,
64 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
65 device_class=SensorDeviceClass.TEMPERATURE,
66 state_class=SensorStateClass.MEASUREMENT,
67 value_fn=
lambda data: data.live_temp,
70 key=PinecilSensor.DC_VOLTAGE,
71 translation_key=PinecilSensor.DC_VOLTAGE,
72 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
73 device_class=SensorDeviceClass.VOLTAGE,
74 state_class=SensorStateClass.MEASUREMENT,
75 value_fn=
lambda data: data.dc_voltage,
76 entity_category=EntityCategory.DIAGNOSTIC,
79 key=PinecilSensor.HANDLETEMP,
80 translation_key=PinecilSensor.HANDLETEMP,
81 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
82 device_class=SensorDeviceClass.TEMPERATURE,
83 state_class=SensorStateClass.MEASUREMENT,
84 value_fn=
lambda data: data.handle_temp,
87 key=PinecilSensor.PWMLEVEL,
88 translation_key=PinecilSensor.PWMLEVEL,
89 native_unit_of_measurement=PERCENTAGE,
90 suggested_display_precision=0,
91 device_class=SensorDeviceClass.POWER_FACTOR,
92 state_class=SensorStateClass.MEASUREMENT,
93 value_fn=
lambda data: data.pwm_level,
94 entity_category=EntityCategory.DIAGNOSTIC,
97 key=PinecilSensor.POWER_SRC,
98 translation_key=PinecilSensor.POWER_SRC,
99 device_class=SensorDeviceClass.ENUM,
100 options=[item.name.lower()
for item
in PowerSource],
101 value_fn=
lambda data: data.power_src.name.lower()
if data.power_src
else None,
102 entity_category=EntityCategory.DIAGNOSTIC,
105 key=PinecilSensor.TIP_RESISTANCE,
106 translation_key=PinecilSensor.TIP_RESISTANCE,
107 native_unit_of_measurement=OHM,
108 value_fn=
lambda data: data.tip_resistance,
109 entity_category=EntityCategory.DIAGNOSTIC,
112 key=PinecilSensor.UPTIME,
113 translation_key=PinecilSensor.UPTIME,
114 native_unit_of_measurement=UnitOfTime.SECONDS,
115 device_class=SensorDeviceClass.DURATION,
116 state_class=SensorStateClass.TOTAL_INCREASING,
117 value_fn=
lambda data: data.uptime,
118 entity_category=EntityCategory.DIAGNOSTIC,
121 key=PinecilSensor.MOVEMENT_TIME,
122 translation_key=PinecilSensor.MOVEMENT_TIME,
123 native_unit_of_measurement=UnitOfTime.SECONDS,
124 device_class=SensorDeviceClass.DURATION,
125 state_class=SensorStateClass.MEASUREMENT,
126 value_fn=
lambda data: data.movement_time,
127 entity_category=EntityCategory.DIAGNOSTIC,
130 key=PinecilSensor.MAX_TIP_TEMP_ABILITY,
131 translation_key=PinecilSensor.MAX_TIP_TEMP_ABILITY,
132 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
133 device_class=SensorDeviceClass.TEMPERATURE,
134 value_fn=
lambda data: data.max_tip_temp_ability,
135 entity_category=EntityCategory.DIAGNOSTIC,
138 key=PinecilSensor.TIP_VOLTAGE,
139 translation_key=PinecilSensor.TIP_VOLTAGE,
140 native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
141 device_class=SensorDeviceClass.VOLTAGE,
142 state_class=SensorStateClass.MEASUREMENT,
143 suggested_display_precision=3,
144 value_fn=
lambda data: data.tip_voltage,
145 entity_category=EntityCategory.DIAGNOSTIC,
148 key=PinecilSensor.HALL_SENSOR,
149 translation_key=PinecilSensor.HALL_SENSOR,
150 state_class=SensorStateClass.MEASUREMENT,
151 entity_registry_enabled_default=
False,
152 value_fn=
lambda data: data.hall_sensor,
153 entity_category=EntityCategory.DIAGNOSTIC,
156 key=PinecilSensor.OPERATING_MODE,
157 translation_key=PinecilSensor.OPERATING_MODE,
158 device_class=SensorDeviceClass.ENUM,
159 options=[item.name.lower()
for item
in OperatingMode],
161 lambda data: data.operating_mode.name.lower()
162 if data.operating_mode
167 key=PinecilSensor.ESTIMATED_POWER,
168 translation_key=PinecilSensor.ESTIMATED_POWER,
169 native_unit_of_measurement=UnitOfPower.WATT,
170 device_class=SensorDeviceClass.POWER,
171 state_class=SensorStateClass.MEASUREMENT,
172 value_fn=
lambda data: data.estimated_power,
179 entry: IronOSConfigEntry,
180 async_add_entities: AddEntitiesCallback,
182 """Set up sensors from a config entry."""
183 coordinator = entry.runtime_data
187 for description
in PINECIL_SENSOR_DESCRIPTIONS
192 """Representation of a IronOS sensor entity."""
194 entity_description: IronOSSensorEntityDescription
198 """Return sensor state."""
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, IronOSConfigEntry entry, AddEntitiesCallback async_add_entities)