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

Amend config to permit json-live-data-server #3

Open
evercape opened this issue Dec 8, 2023 · 5 comments
Open

Amend config to permit json-live-data-server #3

evercape opened this issue Dec 8, 2023 · 5 comments
Labels
enhancement New feature or request work in progress work in progress

Comments

@evercape
Copy link
Owner

evercape commented Dec 8, 2023

Hi Martin,
I use a VBUS/LAN device and have the json-live-data-server running via HA Addon.
It would be great, if your integration could also handle that.
The json-live-data-server is not protected by username and password. Because these settings in your config dialog are mandatory, I cannot try out if the data format of the json-live-data-server is compatible to the KM2 format.
If I can help adding support for VBUS/LAN please tell me.
Regards
Leo

Originally posted by @lebetz in #1 (reply in thread)

@evercape evercape added the enhancement New feature or request label Dec 8, 2023
@lebetz
Copy link

lebetz commented Dec 8, 2023

Hi Martin,
the json-live-data-server returns on endpoint /cgi-bin/get_resol_device_information this data in my case:
device_info.txt

The endpoint /dlx/download/live returns this json:
vbus-live.json

If I see it correct, then km2 and this endpoint return the same format and it should be enough to just decide which endpoint to use like in the original code: https://github.com/dm82m/hass-Deltasol-KM2/blob/1bcb26b45dc04be2a7aa90405bc1e313d01be864/custom_components/deltasol/deltasolapi.py#L140-L166
Regards
Leo

@evercape
Copy link
Owner Author

evercape commented Dec 8, 2023

Thanks Leo, I will check it out tomorrow/over the weekend. Much appreciated for providing the device information and JSON data.
M

@evercape
Copy link
Owner Author

evercape commented Dec 9, 2023

Hi Leo,

I am on Christmas family holidays, only have Laptop, no mouse, no external keyboard, no big screen.....so not ideal...

The following might work:

In resolapi.py line 113 add this method:

def fetch_data_dlx(self):
    response = {}

    url = f"http://{self.host}/dlx/download/live"
    _LOGGER.debug(f"{self.device['serial']}: DLX requesting sensor data from url {url}")

    response = requests.request("GET", url)

    if(response.status_code == 200):
        response_data = response.json()

    _LOGGER.debug(f"DLX response: {response}")

    # Proceed to parsing
    return self.__parse_data(response_data)

In sensor.py line 66 add the following:

   if device_check["product"] == "KM2":
        data = await hass.async_add_executor_job(resol_api.fetch_data_km2)
    elif device_check["product"] == "KM1":
        data = await hass.async_add_executor_job(resol_api.fetch_data_km1)
    elif device_check["product"] == "DL2" or device_check["product"] == "DL3":
        data = await hass.async_add_executor_job(resol_api.fetch_data_dlx)

In config_flow line 54 add the following:

    if device["product"] == "KM2":
        auth_check = await hass.async_add_executor_job(resol_api.fetch_data_km2)
    elif device["product"] == "KM1":
        auth_check = await hass.async_add_executor_job(resol_api.fetch_data_km1)
    elif device["product"] == "DL2" or device["product"] == "DL3":
        auth_check = await hass.async_add_executor_job(resol_api.fetch_data_dlx)

I think it would be best to expose your JSON data for testing via a public IP or DYNDNS, even on Proxmox that might work? If not, I will setup a better test environment when back from holidays, which is only middle of January.

Let me know if the above works, maybe it does.

Also pls just enter anything for username/password for now - if you don't use one then the DL2/3=DLX method is ignoring it for now. Once I can test properly will setup a different config_flow for those type of devices/JSON servers.

Thanks
Martin

@lebetz
Copy link

lebetz commented Dec 9, 2023

Hi Martin,
thanks alot. I only had to add a :{self.port} to the url. And the line to change in resolapi.py was 133 and not 113.
But after these two small changes, it works like a charme.
All Sensors are created correctly.
Regards
Leo

@evercape
Copy link
Owner Author

evercape commented Dec 9, 2023

:{self.port}

...can't believe I forgot that, sorry bout that.

Glad it worked.

I am still not happy with it - I think some people on the json live data server may require username/password and even API key from what I can see.

If you do get a chance to make your setup public (even just whitelist for me) I would like to integrate it and test it properly.

Also with proper exceptions, logging etc. and once properly tested upgrade to a new version of this custom integration.

Pls send me a screenshot how the device looks like if you do get a moment.

Thanks for helping with testing this integration, much appreciated.

Rgds
Martin

@evercape evercape added the work in progress work in progress label Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request work in progress work in progress
Projects
None yet
Development

No branches or pull requests

2 participants