Pigotka / ha-cc-jablotron-cloud

HACS custom component for jablotron cloud integration
GNU General Public License v3.0
12 stars 1 forks source link

0.6.0 does not log in when a user does not have any programmable gates #20

Closed avano closed 3 months ago

avano commented 3 months ago

when trying to log in with the 0.6.0 version I only get:

2024-06-17 12:12:37.407 DEBUG (MainThread) [custom_components.jablotron_cloud] Preparing Jablotron data update coordinator
2024-06-17 12:12:39.433 DEBUG (MainThread) [custom_components.jablotron_cloud] Failed to get gates data for service <service id>
2024-06-17 12:12:39.433 DEBUG (MainThread) [custom_components.jablotron_cloud] Finished fetching Jablotron Cloud data in 2.025 seconds (success: False)

It fails on this line

calling the get_programmable_gates manually using jablotronpy library, it returns {'service-states': {'last-event-time': '2024-06-17T12:08:29+0200', 'service-name': '<name>'}, 'states': []} (with adding print(data) there) and raises the exception here

In the jablotron UI I only have 1 section and 1 keypad - previously I used the section to arm/disarm the alarm using this integration

Pigotka commented 3 months ago

The design principle was to either return data or an UnexpectedResponse as we are returning the entire data from Jablotron instead of parsing the PG's

We could change it so it returns only a list of programmableGates or an empty list. But IIRC you also needed the states in order to map the cloud component ID?

@fdegier The problem is that I'm not able to recognize connection fail from not having the gates. For thermo devices it works well so I would find it resonable to have it unified.

I suggest to return the data whenever they are valid. For gates it would mean for example that 'states' is present in the data.

fdegier commented 3 months ago

The design principle was to either return data or an UnexpectedResponse as we are returning the entire data from Jablotron instead of parsing the PG's

We could change it so it returns only a list of programmableGates or an empty list. But IIRC you also needed the states in order to map the cloud component ID?

@fdegier The problem is that I'm not able to recognize connection fail from not having the gates. For thermo devices it works well so I would find it resonable to have it unified.

I suggest to return the data whenever they are valid. For gates it would mean for example that 'states' is present in the data.

For thermo devices we return states and not a key specific to thermo devices. And that could be an empty list.

Pigotka commented 3 months ago

Right, my interation does not need full data and only programmableGates would be enough but I do not want you to do such breakin changes. I still think you can easily detect whether the response was valid by checking states key instead of programmableGates to allow returnin the data with empty programmableGates.

fdegier commented 3 months ago

Right, my interation does not need full data and only programmableGates would be enough but I do not want you to do such breakin changes. I still think you can easily detect whether the response was valid by checking states key instead of programmableGates to allow returnin the data with empty programmableGates.

The thing is, if a user doesn't have programmable keys, the key is not even present. So I would return a dict with only states.

Pigotka commented 3 months ago

Exactly. As you mentioned earlier. For gates you return all data so this is correct. I'm already checking presence of programmableGates so it would work just fine.

fdegier commented 3 months ago

Exactly. As you mentioned earlier. For gates you return all data so this is correct. I'm already checking presence of programmableGates so it would work just fine.

That is the current situation: https://github.com/fdegier/JablotronPy/blob/255fd4d7fbadbf46da4dc919394cbb393330dc9d/jablotronpy/jablotronpy.py#L278

Pigotka commented 3 months ago

Exactly. As you mentioned earlier. For gates you return all data so this is correct. I'm already checking presence of programmableGates so it would work just fine.

That is the current situation: https://github.com/fdegier/JablotronPy/blob/255fd4d7fbadbf46da4dc919394cbb393330dc9d/jablotronpy/jablotronpy.py#L278

And I suggest: if status and 'states' in data: return data

fdegier commented 3 months ago

Exactly. As you mentioned earlier. For gates you return all data so this is correct. I'm already checking presence of programmableGates so it would work just fine.

That is the current situation: https://github.com/fdegier/JablotronPy/blob/255fd4d7fbadbf46da4dc919394cbb393330dc9d/jablotronpy/jablotronpy.py#L278

And I suggest: if status and 'states' in data: return data

Sorry, I misread the "I'm already checking presence of".

Currently we have: get_services currently returns data['services'] get_thermo_devices returns data['states'] get_keyboard_segments returns data['keyboards'] get_service_history returns data['events'] get_session_id returns data get_sections returns data get_programmable_gates returns data

Shall we unify them all to only check if the request was successful and then returning data ?

Pigotka commented 3 months ago

I'm trying not to introduce breaking changes so I suggest to keep the data format and fix the code so it only throws when the API does not respond properly. It means checking status and if necessary also presence of some key in data but for sessions, sections and gates it might be optional as the existence of the key is not required there.

fdegier commented 3 months ago

New version 0.6.3 allows empty PG

Pigotka commented 3 months ago

Included in new release.

avano commented 3 months ago

Just for the record, the bump of jablotronpy library is not included in 0.6.1 release, but after changing it manually in my installation it works OK