Andre0512 / hon

Home Assistant integration for Haier hOn: support for Haier/Candy/Hoover home appliances like washing machines and air conditioners in 28 languages.
MIT License
1.23k stars 2.49k forks source link

invalid literal for int() #16

Closed alexduf closed 1 year ago

alexduf commented 1 year ago

Hi I've just connected a dishwasher for fun an giggles, here's the stack trace I'm getting.

I'm guessing one of the sensors is expecting an int when the server is returning a float

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 383, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/hon/__init__.py", line 32, in async_setup_entry
    await hon.setup()
  File "/usr/local/lib/python3.10/site-packages/pyhon/api.py", line 61, in setup
    await asyncio.gather(*[
  File "/usr/local/lib/python3.10/site-packages/pyhon/device.py", line 115, in load_commands
    cmd = HonCommand(command, attr2, self._connector, self, multi=multi, program=program)
  File "/usr/local/lib/python3.10/site-packages/pyhon/commands.py", line 13, in __init__
    self._ancillary_parameters = self._create_parameters(attributes.get("ancillaryParameters", {}))
  File "/usr/local/lib/python3.10/site-packages/pyhon/commands.py", line 23, in _create_parameters
    result[parameter] = HonParameterRange(parameter, attributes)
  File "/usr/local/lib/python3.10/site-packages/pyhon/parameter.py", line 51, in __init__
    self._min = int(attributes["minimumValue"])
ValueError: invalid literal for int() with base 10: '0,5'
Andre0512 commented 1 year ago

Hi, I fixed it and cast it to a float now. I created a new beta release v0.5.0-beta.2.

Andre0512 commented 1 year ago

Whoops I messed up, please try version v0.5.0-beta.3 :slightly_smiling_face:

alexduf commented 1 year ago

Hey thanks for your quick responses!

Something that worries me a little and that I noticed later was how the value is using a coma instead of a dot to separate digits. ValueError: invalid literal for int() with base 10: '0,5'

I'm in France and I'm wondering if the server is formatting that to whatever locale the user is in (we would format it 0,5 in France as opposed to 0.5 in the US). Yesterday I hacked around and got it to work by casting to floats as you did, but I also had to replace , with ., which felt very hack-ish because if it were indeed formatting to a specific locale then the parsing might be more complicated :/

Andre0512 commented 1 year ago

Hey, I take care of it and also used a replace. I saw this and found it also a little strange why they localize the api values. But here in Germany we also use comma as separator and I know these formatting problems well. I think this isn't going to be a big problem when using the replace, if it's already a dot than just nothing gets replaced. For my washing machine there is a delay parameter with values that can go above 1000 and they doesn't use a thousand separator there, so I think this also wouldn't be a problem.

alexduf commented 1 year ago

Brilliant, I'll test your patch tonight, thanks for your help!

alexduf commented 1 year ago

Hey thanks, I can confirm the fix works. I'll look into supporting DW devices though I can't promise anything.