www-ShapeLabs-de / Judo-i-soft-save-plus-to-mqtt-bridge

A small device to write and read settings to Judo i-soft safe+ water softening system with homeassistant
MIT License
20 stars 6 forks source link

Little endian hex string helper function #3

Closed hzulla closed 1 year ago

hzulla commented 1 year ago

https://github.com/www-ShapeLabs-de/Judo-i-soft-save-plus-to-mqtt-bridge/blob/9ea6f6145c0fc38f97e52bdf989079c6f3950e3e/python/getjudo.py#L214-L215

Hi,

this is an artefact from converting a little endian hex string. It may be more readable to do it this way:

def le_hex_to_int(hexstring):
    # convert little endian hex to integer
    return int.from_bytes(bytes.fromhex(hexstring), byteorder='little')

# ...

total_water.value = float(le_hex_to_int(val[0:8])/1000

and accordingly for the other little endian hex strings used in the code.

www-ShapeLabs-de commented 1 year ago

Thank you, that's a good idea to use a small function for this. My code has grown from a test where I do this manually. At some point you get used to it and overlook that it can be done more elegantly :-D