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

Home Assistant 2022.7: LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity #929

Closed
pimw1 opened this issue Jul 2, 2022 · 13 comments
Labels
bug Something isn't working

Comments

@pimw1
Copy link

pimw1 commented Jul 2, 2022

The problem

Per Home Assistant 2022.7, i receive the following warning. There is no functional impact yet (which makes sense, it will sart breaking in version 2022.10). Local Tuya is making use of a to-be-deprecated mtehod.

Logger: homeassistant.components.number
Source: components/number/__init__.py:220
Integration: Number (documentation, issues)
First occurred: 21:15:12 (1 occurrences)
Last logged: 21:15:12

custom_components.localtuya.number::LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity, this is not valid and will be unsupported from Home Assistant 2022.10. Please report it to the custom component author.

Environment

  • Localtuya version: 4.0.1
  • Last working localtuya version (if known and relevant): 4.0.1
  • Home Assistant Core version: 2022.7b2
  • [] Are you using the Home Assistant Tuya Cloud component ?
  • [] Are you using the Tuya App in parallel ?

Steps to reproduce

  1. Update from Home Assistant 2022.6 to 2022.7 (currently still in beta)
  2. check the logs of home assistant after a reboot

Configuration configuration.yaml or config_flow

DP dump

Provide Home Assistant taceback/logs

Additional information

@pimw1 pimw1 added the bug Something isn't working label Jul 2, 2022
@vaibhav2912
Copy link

I updated to HA core 2022.7 today and I see the same warning.

Logger: homeassistant.components.number
Source: components/number/__init__.py:220
Integration: Number (documentation, issues)
First occurred: 10:24:41 PM (1 occurrences)
Last logged: 10:24:41 PM

custom_components.localtuya.number::LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity, this is not valid and will be unsupported from Home Assistant 2022.10. Please report it to the custom component author.

markvader added a commit to markvader/localtuya that referenced this issue Jul 7, 2022
Relates to issues [929](rospogrigio#929), [939](rospogrigio#939) & [941](rospogrigio#941)
I do not have any suitable tuya devices in use to test against this number entity however the warning in logs "LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity] is now gone

https://developers.home-assistant.io/blog/2022/06/14/number_entity_refactoring/
@smarthomefamilyverrips
Copy link

Will follow here for updates 👍🏻

@smarthomefamilyverrips
Copy link

#944

Using the changes in this commit/pull request worked for me. Thanks!

@DCG81
Copy link

DCG81 commented Jul 21, 2022

same problem I am facing

Logger: homeassistant.components.number
Source: components/number/init.py:220
Integration: Number (documentation, issues)
First occurred: 2:20:12 AM (1 occurrences)
Last logged: 2:20:12 AM

custom_components.localtuya.number::LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity, this is not valid and will be unsupported from Home Assistant 2022.10. Please report it to the custom component author.

suddenly my Local Tuya devices go offline and I need to restart HA to fix it

@DCG81
Copy link

DCG81 commented Jul 21, 2022

#944

Using the changes in this commit/pull request worked for me. Thanks!

hey how do we do this? pls help

@smarthomefamilyverrips
Copy link

smarthomefamilyverrips commented Jul 21, 2022

#944
Using the changes in this commit/pull request worked for me. Thanks!

hey how do we do this? pls help

You will need to make the changes manually to the custom_components/localtuya/number.py file using file editor.

@DCG81
Copy link

DCG81 commented Jul 21, 2022

#944
Using the changes in this commit/pull request worked for me. Thanks!

hey how do we do this? pls help

You will need to make the changes manually to the custom_components/localtuya/number.py file using file editor.

yes did that and it worked, thanks :)

Noltari pushed a commit to Noltari/localtuya that referenced this issue Aug 5, 2022
Relates to issues [929](rospogrigio#929), [939](rospogrigio#939) & [941](rospogrigio#941)
I do not have any suitable tuya devices in use to test against this number entity however the warning in logs "LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity] is now gone

https://developers.home-assistant.io/blog/2022/06/14/number_entity_refactoring/
@sebaschn
Copy link

sebaschn commented Aug 11, 2022

#944
Using the changes in this commit/pull request worked for me. Thanks!

hey how do we do this? pls help

You will need to make the changes manually to the custom_components/localtuya/number.py file using file editor.

obviously newbie here.
i've read the blog post ( https://developers.home-assistant.io/blog/2022/06/14/number_entity_refactoring/ )
a few times now. but still i have no clue what exactly i have to change.
what (now buggy) code do i have to turn into what new code?
thank you in advance!!

thats my "number.py" code:

"""Platform to present any Tuya DP as a number."""
import logging
from functools import partial

import voluptuous as vol
from homeassistant.components.number import DOMAIN, NumberEntity
from homeassistant.const import CONF_DEVICE_CLASS, STATE_UNKNOWN

from .common import LocalTuyaEntity, async_setup_entry

_LOGGER = logging.getLogger(__name__)

CONF_MIN_VALUE = "min_value"
CONF_MAX_VALUE = "max_value"

DEFAULT_MIN = 0
DEFAULT_MAX = 100000


def flow_schema(dps):
    """Return schema used in config flow."""
    return {
        vol.Optional(CONF_MIN_VALUE, default=DEFAULT_MIN): vol.All(
            vol.Coerce(float),
            vol.Range(min=-1000000.0, max=1000000.0),
        ),
        vol.Required(CONF_MAX_VALUE, default=DEFAULT_MAX): vol.All(
            vol.Coerce(float),
            vol.Range(min=-1000000.0, max=1000000.0),
        ),
    }


class LocaltuyaNumber(LocalTuyaEntity, NumberEntity):
    """Representation of a Tuya Number."""

    def __init__(
        self,
        device,
        config_entry,
        sensorid,
        **kwargs,
    ):
        """Initialize the Tuya sensor."""
        super().__init__(device, config_entry, sensorid, _LOGGER, **kwargs)
        self._state = STATE_UNKNOWN

        self._min_value = DEFAULT_MIN
        if CONF_MIN_VALUE in self._config:
            self._min_value = self._config.get(CONF_MIN_VALUE)

        self._max_value = self._config.get(CONF_MAX_VALUE)

    @property
    def value(self) -> float:
        """Return sensor state."""
        return self._state

    @property
    def min_value(self) -> float:
        """Return the minimum value."""
        return self._min_value

    @property
    def max_value(self) -> float:
        """Return the maximum value."""
        return self._max_value

    @property
    def device_class(self):
        """Return the class of this device."""
        return self._config.get(CONF_DEVICE_CLASS)

    async def async_set_value(self, value: float) -> None:
        """Update the current value."""
        await self._device.set_dp(value, self._dp_id)

    def status_updated(self):
        """Device status was updated."""
        state = self.dps(self._dp_id)
        self._state = state


async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaNumber, flow_schema)

@ElStupid
Copy link

@sebaschn See https://github.com/rospogrigio/localtuya/pull/944/files for the changes you have to make (red lines are old, green lines are new, blue and white ones unchanged)

Ran into this problem just today

@sebaschn
Copy link

@ElStupid
i thank you so much!
i've changed the code - and for now (?) it works!
(just in case, i've left the old code in BUT disabled it with "#" )

genehand pushed a commit to genehand/localtuya that referenced this issue Aug 18, 2022
Relates to issues [929](rospogrigio#929), [939](rospogrigio#939) & [941](rospogrigio#941)
I do not have any suitable tuya devices in use to test against this number entity however the warning in logs "LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity] is now gone

https://developers.home-assistant.io/blog/2022/06/14/number_entity_refactoring/
@Yonny24
Copy link

Yonny24 commented Aug 27, 2022

I still have local tuya down even after updating number.py manually.
Please advise. Thanks

2022.8.7

`Logger: homeassistant
Source: custom_components/localtuya/common.py:117
Integration: LocalTuya (documentation, issues)
First occurred: 9:18:30 PM (108 occurrences)
Last logged: 9:19:05 PM

Error doing job: Exception in callback _SelectorDatagramTransport._read_ready()
Traceback (most recent call last):
File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 1027, in _read_ready
self._protocol.datagram_received(data, addr)
File "/config/custom_components/localtuya/discovery.py", line 70, in datagram_received
self.device_found(decoded)
File "/config/custom_components/localtuya/discovery.py", line 79, in device_found
self._callback(device)
File "/config/custom_components/localtuya/init.py", line 105, in _device_discovered
entry = async_config_entry_by_device_id(hass, device_id)
File "/config/custom_components/localtuya/common.py", line 117, in async_config_entry_by_device_id
if device_id in entry.data[CONF_DEVICES]:
KeyError: 'devices'`

rospogrigio pushed a commit that referenced this issue Aug 29, 2022
Relates to issues [929](#929), [939](#939) & [941](#941)
I do not have any suitable tuya devices in use to test against this number entity however the warning in logs "LocaltuyaNumber is overriding deprecated methods on an instance of NumberEntity] is now gone

https://developers.home-assistant.io/blog/2022/06/14/number_entity_refactoring/
@CloCkWeRX
Copy link

Now closable

@pimw1
Copy link
Author

pimw1 commented Aug 30, 2022

#944 fixed the isssue. Thanks for all the help!

@pimw1 pimw1 closed this as completed Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants