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

DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_MOTION & BinarySensorDeviceClass.DOOR deprecated constant which will be removed in HA Core 2025.1 #232

Open
jlgandy2 opened this issue Jan 20, 2024 · 20 comments

Comments

@jlgandy2
Copy link

I am seeing in the logs the following:
DEVICE_CLASS_TIMESTAMP was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.TIMESTAMP instead, please report it to the author of the 'wyzesense' custom integration
DEVICE_CLASS_MOTION was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use BinarySensorDeviceClass.MOTION instead, please report it to the author of the 'wyzesense' custom integration
DEVICE_CLASS_DOOR was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use BinarySensorDeviceClass.DOOR instead, please report it to the author of the 'wyzesense' custom integration

Is this something easy to update?

@stanwebber
Copy link

when the time comes i hope it will be as simple as find and replace all. kinda irritating this is happening yet again.

@tggman
Copy link

tggman commented Jun 11, 2024

I tried a simple find/replace but my code editor (Visual Studio Code) flagged the python syntax as incorrect and I don't know python.

I know @kevinvincent flagged this integration as no longer supported, but perhaps he could help us out/point us in the right direction? It's amazing that this code is still in use considering the effort required to keep the sensors in play - which in my case means aggressively monitoring battery life.

@jcauble
Copy link

jcauble commented Oct 5, 2024

@tggman I believe I was able to get this error to go away. Try replacing your binary_sensor.py file with the attached. I changed lines 23, 25, and 90. I know very little about python, I just looked at another integration I had with the same file and tried to understand how it was done there.
binary_sensor.zip

Line 23:
previous:
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity, DEVICE_CLASS_MOTION, DEVICE_CLASS_DOOR
updated:
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity, BinarySensorDeviceClass

Line 25:
previous:
from homeassistant.components.binary_sensor import BinarySensorDevice as BinarySensorEntity, PLATFORM_SCHEMA, DEVICE_CLASS_MOTION, DEVICE_CLASS_DOOR
updated:
from homeassistant.components.binary_sensor import BinarySensorDevice as BinarySensorEntity, PLATFORM_SCHEMA, BinarySensorDeviceClass

Line 90:
previous:
ATTR_DEVICE_CLASS: DEVICE_CLASS_MOTION if sensor_type == "motion" else DEVICE_CLASS_DOOR ,
updated:
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.MOTION if sensor_type == "motion" else BinarySensorDeviceClass.DOOR ,

@tggman
Copy link

tggman commented Oct 6, 2024

Thanks so much @jcauble! Really appreciate your detailed help and patch. Your fixes eliminated 2 out of the 3 errors in the log and WyseSense seems to be functioning as expected. Awesome. Thanks again.

I followed your logic in an attempt to fix the DEVICE_CLASS_TIMESTAMP error but had to revert those changes back when I received all sorts of errors in the log. Have you had any luck fixing this error?

Here are the changes I tried / made to binary_sensor.py which resulted in those log errors and which I reverted back:

  • Line 20:
    Replaced ATTR_STATE, ATTR_DEVICE_CLASS, DEVICE_CLASS_TIMESTAMP
    with ATTR_STATE, ATTR_DEVICE_CLASS, SensorDeviceClass
  • Line 91:
    replaced DEVICE_CLASS_TIMESTAMP: event.Timestamp.isoformat(),
    with SensorDeviceClass.TIMESTAMP : event.Timestamp.isoformat(),

Any additional help you can provide would be greatly appreciated.

@jcauble
Copy link

jcauble commented Oct 6, 2024

@tggman I’m not seeing that error, where do you see it? I’m running HA 2024.10.1. I saw the errors for door and motion in my home assistant logs, but I only noticed them because I was having an unrelated problem with Wyzesense.

@tggman
Copy link

tggman commented Oct 6, 2024

I too am running HAC 2024.10.1

The error:
DEVICE_CLASS_TIMESTAMP was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.TIMESTAMP instead, please report it to the author of the 'wyzesense' custom integration

... is under Settings/System/Logs - just like the other 2. Your error msg might be burried/reported in the same block with similar errors - like for example, the nest_protect error in the following:

Logger: homeassistant.const
Source: helpers/deprecation.py:197
First occurred: 9:37:15 AM (2 occurrences)
Last logged: 9:37:33 AM

DEVICE_CLASS_TIMESTAMP was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.TIMESTAMP instead, please report it to the author of the 'wyzesense' custom integration
TEMP_CELSIUS was used from nest_protect, this is a deprecated constant which will be removed in HA Core 2025.1. Use UnitOfTemperature.CELSIUS instead, please report it to the author of the 'nest_protect' custom integration

@tggman
Copy link

tggman commented Oct 6, 2024

I figured out the fix. Here are the changes I made:

At Line 17:
Add: from homeassistant.components.sensor import SensorDeviceClass

At line 20:
Replace: ATTR_STATE, ATTR_DEVICE_CLASS, DEVICE_CLASS_TIMESTAMP
With: ATTR_STATE, ATTR_DEVICE_CLASS

At Line 91:
Replace: DEVICE_CLASS_TIMESTAMP: event.Timestamp.isoformat(),
With: SensorDeviceClass.TIMESTAMP: event.Timestamp.isoformat(),

Here's the revised file:
binary_sensor.zip

@User873902
Copy link

Hey this is great! I applied the above patch, but I'm still having problems with my wyze contact sensors (v2) not reporting back to HA. They seem to have stopped working on 9/25 which would have been the update to 2024.9.3. I am currently running 2024.10.1. I tired replacing the battery in one door sensor, but still no change.

I see you are running 2024.10.1. Assuming your sensors are working, is there another fix you implemented as well?

@jcauble
Copy link

jcauble commented Oct 7, 2024

You might try unplugging the usb dongle, plugging it back in, and restarting home assistant. I’ve had this happen numerous times and this fixes it.

@User873902
Copy link

You might try unplugging the usb dongle, plugging it back in, and restarting home assistant. I’ve had this happen numerous times and this fixes it.

Beautiful. This was it. Thanks!

@stewjoel
Copy link

stewjoel commented Nov 3, 2024

I am seeing in the logs the following: DEVICE_CLASS_TIMESTAMP was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use SensorDeviceClass.TIMESTAMP instead, please report it to the author of the 'wyzesense' custom integration DEVICE_CLASS_MOTION was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use BinarySensorDeviceClass.MOTION instead, please report it to the author of the 'wyzesense' custom integration DEVICE_CLASS_DOOR was used from wyzesense, this is a deprecated constant which will be removed in HA Core 2025.1. Use BinarySensorDeviceClass.DOOR instead, please report it to the author of the 'wyzesense' custom integration

Is this something easy to update?

I've updated the code to resolve the all of the errors. Feel free to try out my newer code. https://github.com/stewjoel/ha-wyzesense/

@stanwebber
Copy link

i applied stewjoel's edits to binary_sensor.py in my own fork. so far so good. the commits did overwrite the previous fix i applied from issue #189 so we'll see how that goes.

            # From https://github.com/kevinvincent/ha-wyzesense/issues/189
            try:
                entities[event.MAC].schedule_update_ha_state()
            except (AttributeError, AssertionError):
                _LOGGER.debug("wyze Sensor not yet ready for update")

replaced with:

            hass.add_job(entities[event.MAC].async_write_ha_state)
async def update_storage(hass, mac):
    storage = await getStorage(hass)
    if mac not in storage:
        storage.append(mac)
        await setStorage(hass, storage)

@stanwebber
Copy link

stanwebber commented Dec 15, 2024

for the life of me i can't figure out why @stewjoel fixes have now made this integration incompatible with hacs. i've tried completely uninstalling/reinstalling and have modified the manifest.json to remove all the install requirements or alternately add "aiofiles==0.4.0". no matter what i try i still get the error:

the version xxxxxx for this integration can not be used with hacs

hacs does some asinine parsing of the python scripts instead of just copying them to the custom_components directory (which works manually without fail so making hacs happy is the problem here).

@tggman
Copy link

tggman commented Dec 15, 2024

I figured out the fix. Here are the changes I made:

At Line 17: Add: from homeassistant.components.sensor import SensorDeviceClass

At line 20: Replace: ATTR_STATE, ATTR_DEVICE_CLASS, DEVICE_CLASS_TIMESTAMP With: ATTR_STATE, ATTR_DEVICE_CLASS

At Line 91: Replace: DEVICE_CLASS_TIMESTAMP: event.Timestamp.isoformat(), With: SensorDeviceClass.TIMESTAMP: event.Timestamp.isoformat(),

Here's the revised file: binary_sensor.zip

All I can tell you is that the above changes fixed the issue for me with no adverse consequences.

@stewjoel
Copy link

@tggman Somehow I entirely missed your fix. That's great and may have saved me some time. @stanwebber I honestly haven't even looked at the HACS issue. I don't necessarily want to spend the time considering that there is maybe only a handful of people using this and manually adding to the custom_components is a simple process. If anyone wants to spend time looking at it, feel free to push changes to my branch and I can take a look.

@User873902
Copy link

I just wanted to say that I use this integration and am extremely grateful for any efforts made for continuing support! Thanks all!

@stanwebber
Copy link

ok, i figured out the problem with hacs. my fork did not have any associated tags so i published a release with the tag matching the version listed in the manifest.json and hacs is happy now.

incidentally, i discovered erlanger (authored pull request for issue #189) published a fix in his fork for deprecated device_class_timestamp/motion/door back in april. i'm trying out his code right now and it also appears to be solid.

@worldgod13
Copy link

Thanks for keeping this going guys! I still have half a dozen of the motion sensors in use and with the latest HA update they all stopped working. I replaced the binary_sensor.py and they all work again. Thank you so much. I do not have to buy all new sensors for the time being. I really appreciate it!

@filgr8
Copy link

filgr8 commented Jan 4, 2025

Thank You @tggman

@otiswrx
Copy link

otiswrx commented Jan 4, 2025

Just coming here to say thank you to all of the above for this (how to) fix. I've been ignoring the logs warning of this latest HA update breaking the wyzesense integration. Then I remembered this issue having the solutions! @tggman @jcauble @stewjoel much appreciated!

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

9 participants