cdpuk / ha-bestway

Home Assistant integration for Bestway / Lay-Z-Spa hot tubs
MIT License
71 stars 18 forks source link

Add support for Hydrojet_Pro #52

Closed thecadams closed 7 months ago

thecadams commented 7 months ago

With this script:

from bestway.api import BestwayApi
import aiohttp
import asyncio

async def main():
    async with aiohttp.ClientSession() as session:
        token = await BestwayApi.get_user_token(session, 'XXX', 'XXX', 'https://usapi.gizwits.com')
        api = BestwayApi(session, token.user_token, 'https://usapi.gizwits.com')
        print('@@@', await api.refresh_bindings())
        print('!!!', await api.fetch_data())

asyncio.run(main())

I got the following output for my Hydrojet Pro:

@@@ Status for unknown device type 'Hydrojet_Pro' returned: {"E19": 0, "E18": 0, "E32": 1, "E31": 0, "E30": 0, "E11": 0, "E10": 0, "E13": 0, "E12": 0, "E15": 0, "E14": 0, "E17": 0, "E16": 0, "word5": 12747, "word4": 0, "word7": 39, "word6": 0, "word1": 0, "word0": 0, "E29": 0, "word2": 12747, "option6": 10244, "ver": 934, "E22": 0, "jet": 0, "E23": 0, "power": 1, "Tnow": 39, "option7": 10260, "option4": 60, "option5": 27175, "option2": 0, "option3": 30, "option0": 59940, "option1": 59940, "E24": 0, "E25": 0, "E26": 0, "E27": 0, "E20": 0, "E21": 0, "E08": 0, "E09": 0, "E06": 0, "E07": 0, "E04": 0, "E05": 0, "E02": 0, "E03": 0, "E01": 0, "bit7": 1, "heat": 4, "Tunit": 1, "wave": 0, "word3": 0, "Tset": 39, "filter": 2, "E28": 0, "bit6": 1, "bit5": 0, "bit4": 0, "bit3": 0, "bit2": 1}
!!! BestwayApiResults(devices={'rp5Hx6xMxGGkS27hvpICnO': BestwayDeviceStatus(timestamp=1708322029, attrs={'E19': 0, 'E18': 0, 'E32': 1, 'E31': 0, 'E30': 0, 'E11': 0, 'E10': 0, 'E13': 0, 'E12': 0, 'E15': 0, 'E14': 0, 'E17': 0, 'E16': 0, 'word5': 12747, 'word4': 0, 'word7': 39, 'word6': 0, 'word1': 0, 'word0': 0, 'E29': 0, 'word2': 12747, 'option6': 10244, 'ver': 934, 'E22': 0, 'jet': 0, 'E23': 0, 'power': 1, 'Tnow': 39, 'option7': 10260, 'option4': 60, 'option5': 27175, 'option2': 0, 'option3': 30, 'option0': 59940, 'option1': 59940, 'E24': 0, 'E25': 0, 'E26': 0, 'E27': 0, 'E20': 0, 'E21': 0, 'E08': 0, 'E09': 0, 'E06': 0, 'E07': 0, 'E04': 0, 'E05': 0, 'E02': 0, 'E03': 0, 'E01': 0, 'bit7': 1, 'heat': 4, 'Tunit': 1, 'wave': 0, 'word3': 0, 'Tset': 39, 'filter': 2, 'E28': 0, 'bit6': 1, 'bit5': 0, 'bit4': 0, 'bit3': 0, 'bit2': 1})})

Almost all the fields referenced by the Hydrojet code are there - but the error codes are different, so I added a new error code sensor. I only included the codes in the manual at https://support.bestwayaftersales.co.uk/wp-content/uploads/2020/01/Maldives-HJ-Pro-2020.pdf , although my API output didn't have earth so I've made it not raise if that key is missing.

I'd like to test this in my HA setup, do I just add my own repo as a custom repo? Or are there extra steps like publishing it to HACS?

thecadams commented 7 months ago

Tested by adding my own repo to HACS and it's working (unrelated there is the power socket showing the heater running at 1800W..)

Screenshot 2024-02-19 at 8 55 38 pm Screenshot 2024-02-19 at 9 40 51 pm
thecadams commented 7 months ago

And can I just say thank you for the quality of the code as well! It was very easy to test with just the API and very easy to see how to add my changes and test, as you can see I went from knowing nothing as a first-time HA users, to raising a ticket, to making a PR, to demonstrating it working, in only a couple hours.

Very cool. Thanks for the great work on the module!

cdpuk commented 7 months ago

Hi @thecadams, thanks for your contribution and kind words 😄

I've made some minor tweaks for code style, but one thing to note is that I've removed the proposed errors sensor. I've seen the same error values for a number of other models, but since errors rarely happen, nobody has ever been able to confirm exactly how the API values correspond to what's seen on the spa display. I'm trying to avoid adding code based on guesswork, so we'll leave that out for now.

I'll force this through ignoring the unrelated test failure.

thecadams commented 7 months ago

@cdpuk you’re welcome - and that's a shame about removing the error handling, because I’ve had the E02 happen against my fork with the PR as submitted (flow rate sensor tripped due to a dirty filter) and it was caught and my automation triggered, which (unrelated to this PR) switched off power to the tub.

So I do think the code is correct as submitted and strongly recommend adding that error handling back in.

Either way thanks again for your great work on this module!