Compilation fails on ESPHome 2026.2.4 — set_unit_of_measurement and set_device_class not found
Disclosure: I'm not a programmer — I arrived at this diagnosis with help from Claude (Anthropic's AI assistant), which walked me through the setup and helped troubleshoot. I wanted to be transparent about that.
Environment
- ESPHome version: 2026.2.4
- ESPHome installed via: Home Assistant Add-on
- Board: ESP32-S3-DevKitC-1 (N16R8)
- Framework: ESP-IDF
- UPS: CyberPower CP1500PFCLCD
Description
The component fails to compile on ESPHome 2026.2.4. The generated C++ code calls set_unit_of_measurement() and set_device_class() on UpsHidSensor and UpsHidBinarySensor, but these methods don't exist on those classes.
It appears that ESPHome 2026.x changed how sensor properties are set — the set_unit_of_measurement and set_device_class methods were removed or renamed on the base Sensor class. The component's Python codegen (sensor.py, binary_sensor.py) still generates calls to the old API.
Steps to Reproduce
Minimal config:
esphome:
name: ups-monitor
friendly_name: UPS Monitor
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
logger:
level: DEBUG
hardware_uart: UART0
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
ota:
- platform: esphome
external_components:
- source: github://bullshit/esphome-components
components: [ups_hid, nut_server]
ups_hid:
id: ups_monitor
update_interval: 10s
protocol: cyberpower
simulation_mode: true
sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Battery Level"
type: battery_level
binary_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "Online"
type: online
text_sensor:
- platform: ups_hid
ups_hid_id: ups_monitor
name: "UPS Status"
type: status
button:
- platform: ups_hid
name: "Beeper Enable"
beeper_action: enable
number:
- platform: ups_hid
name: "Shutdown Delay"
delay_type: shutdown
nut_server:
ups_hid_id: ups_monitor
port: 3493
Compile Errors (truncated)
src/main.cpp:378:18: error: 'class esphome::ups_hid::UpsHidSensor' has no member named 'set_unit_of_measurement'; did you mean 'get_unit_of_measurement'?
378 | battery_level->set_unit_of_measurement("%");
src/main.cpp:379:18: error: 'class esphome::ups_hid::UpsHidSensor' has no member named 'set_device_class'; did you mean 'get_device_class'?
379 | battery_level->set_device_class("battery");
src/main.cpp:597:34: error: 'class esphome::ups_hid::UpsHidBinarySensor' has no member named 'set_device_class'; did you mean 'get_device_class'?
597 | ups_hid_upshidbinarysensor_id->set_device_class("battery");
The same pattern repeats for every sensor and binary_sensor entry.
Notes
- Simulation mode works on older firmware — when the component successfully compiled (possibly cached from an earlier ESPHome version), simulation mode booted and ran correctly, registering all sensors and polling data.
- The
button and number platforms compile fine — only sensor and binary_sensor are affected.
- The issue is in the Python codegen, not the C++ runtime —
UpsHidSensor inherits from a base class that no longer exposes set_unit_of_measurement() as a public method in ESPHome 2026.x.
- We also confirmed that
hardware_uart: UART0 is needed in the logger config to free up the native USB port for USB host mode — without it, the USB JTAG serial interface claims the port and the UPS HID transport cannot connect.
Compilation fails on ESPHome 2026.2.4 —
set_unit_of_measurementandset_device_classnot foundDisclosure: I'm not a programmer — I arrived at this diagnosis with help from Claude (Anthropic's AI assistant), which walked me through the setup and helped troubleshoot. I wanted to be transparent about that.
Environment
Description
The component fails to compile on ESPHome 2026.2.4. The generated C++ code calls
set_unit_of_measurement()andset_device_class()onUpsHidSensorandUpsHidBinarySensor, but these methods don't exist on those classes.It appears that ESPHome 2026.x changed how sensor properties are set — the
set_unit_of_measurementandset_device_classmethods were removed or renamed on the baseSensorclass. The component's Python codegen (sensor.py,binary_sensor.py) still generates calls to the old API.Steps to Reproduce
Minimal config:
Compile Errors (truncated)
The same pattern repeats for every sensor and binary_sensor entry.
Notes
buttonandnumberplatforms compile fine — onlysensorandbinary_sensorare affected.UpsHidSensorinherits from a base class that no longer exposesset_unit_of_measurement()as a public method in ESPHome 2026.x.hardware_uart: UART0is needed in the logger config to free up the native USB port for USB host mode — without it, the USB JTAG serial interface claims the port and the UPS HID transport cannot connect.