Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'DEVICE_CLASS_TEMPERATURE' error with HA 2025.1.0 #8

Open
ericdechaux opened this issue Jan 6, 2025 · 4 comments

Comments

@ericdechaux
Copy link

Since Home assistant update 2025.1.0 the integration generate an error :

ImportError: cannot import name 'DEVICE_CLASS_TEMPERATURE' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)

i ve read that DEVICE_CLASS_TEMPERATURE have been removed from home assistant const.

Is it possible to correct code

best regards

@ChrisSutton123
Copy link

Comment out the following in sensor.py:-
#from homeassistant.const import (

DEVICE_CLASS_TEMPERATURE,

DEVICE_CLASS_HUMIDITY,

DEVICE_CLASS_ILLUMINANCE,

DEVICE_CLASS_CO2,

DEVICE_CLASS_BATTERY

#)

Then change:-
if sensor_id == "3000":
self._attr_device_class = DEVICE_CLASS_BATTERY
elif self.sensor_id == '4097' or self.sensor_id == '4102':
self._attr_device_class = DEVICE_CLASS_TEMPERATURE
elif self.sensor_id == '4098' or self.sensor_id == '4103':
self._attr_device_class = DEVICE_CLASS_HUMIDITY
elif self.sensor_id == '4099' or self.sensor_id == '4193' or self.sensor_id == '4199':
self._attr_device_class = DEVICE_CLASS_ILLUMINANCE
elif self.sensor_id == '4100':
self._attr_device_class = DEVICE_CLASS_CO2

To:-
if sensor_id == "3000":
self._attr_device_class = SensorDeviceClass.BATTERY
elif self.sensor_id == '4097' or self.sensor_id == '4102':
self._attr_device_class = SensorDeviceClass.TEMPERATURE
elif self.sensor_id == '4098' or self.sensor_id == '4103':
self._attr_device_class = SensorDeviceClass.HUMIDITY
elif self.sensor_id == '4099' or self.sensor_id == '4193' or self.sensor_id == '4199':
self._attr_device_class = SensorDeviceClass.ILLUMINANCE
elif self.sensor_id == '4100':
self._attr_device_class = SensorDeviceClass.CO2

In custom_components/sensecap/sensor.py
then
REBOOT HA

@ericdechaux
Copy link
Author

The correction is working, no more error in the integration.
i have suppressed all about my devices ( maps entities etc) in HA before doing the opéraiton but now they are not détected ( no notification). How do i manualy launch the detection ?

best regards
-:)

@ChrisSutton123
Copy link

Sorry I don't understand:-

i have suppressed all about my devices ( maps entities etc) in HA before doing the opéraiton but now they are not détected ( no notification)

@ericdechaux
Copy link
Author

sorry i ve solved the second problem.

tanks a lot for your help i can now monitor the green houses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants