Szaki-dev / tuya_fix

8 stars 0 forks source link

Clarify the patch / diff #1

Closed dcarosone closed 6 months ago

dcarosone commented 8 months ago

Could you clarify the patch / diff / original revision this was copied from?

I'd like to apply this to my system, but I feel it's better done as a patch (applied via overlay as part of the nix packaging, in my case) so it doesn't stop any other fixes. It would also be more helpful as a submission upstream assuming it's correct for more than just this one device.

In the meantime, I've done the template workaround.

Szaki-dev commented 8 months ago

Hi, Thank you for your interest. In the original code, scaling was implemented as follows:

@property
def step_scaled(self) -> float:
    """Return the step scaled."""
    return self.step / (10**self.scale)

def scale_value(self, value: float | int) -> float:
    """Scale a value."""
    return value / (10**self.scale)

def scale_value_back(self, value: float | int) -> int:
    """Return raw value for scaled."""
    return int(value * (10**self.scale))

This code is from the original homeassistant/core -> tuya component base.py file. As you can see it here In my modification, scaling is fixed at 10:

@property
def step_scaled(self) -> float:
    """Return the step scaled."""
    return self.step / (10**1)

def scale_value(self, value: float | int) -> float:
    """Scale a value."""
    return value / (10**1)

def scale_value_back(self, value: float | int) -> int:
    """Return raw value for scaled."""
    return int(value * (10**1))

I wanted the most minimal modification to the code. Everything else is the same as the original. In my case everytime I manually set the scaling number it got overwritten after next update. I hope this helps. :D