gpulido / python-airzone

MIT License
10 stars 3 forks source link

0.8.1, error, Zones #15

Closed Mike-de-bike closed 3 years ago

Mike-de-bike commented 3 years ago

@gpulido Following error in airzone_cli is active: stefan@pizzabox:~/homeassistant/custom_components/airzone$ airzone_cli.py --system localapi --machine 1 192.168.90.9 3000 [!] [500] Server Error Traceback (most recent call last): File "/home/stefan/.local/bin/airzone_cli.py", line 34, in <module> args.func(args) File "/home/stefan/.local/bin/airzone_cli.py", line 18, in action print(str(m)) File "/home/stefan/.local/lib/python3.7/site-packages/airzone/localapi.py", line 143, in __str__ "\nZones\n" + zs File "/home/stefan/.local/lib/python3.7/site-packages/airzone/localapi.py", line 125, in operation_mode return OperationMode(self._get_zone_property(0, 'mode')) File "/home/stefan/.local/lib/python3.7/site-packages/airzone/localapi.py", line 106, in _get_zone_property z_id = next(iter(self._zones)) StopIteration

gpulido commented 3 years ago

@Mike-de-bike The error is that the server is answering with a 500. I have created a new branch requests_error where we print more info regarding the server answer to know what is happening there. Could you try to execute it and write the info back please? Thanks!

Mike-de-bike commented 3 years ago

Hello @gpulido 500 means that the request is malformed.

Mike-de-bike commented 3 years ago

Hello @gpulido The api returns maximal two error codes: 200 ann 500. It seems, something is running out of line in airzone-cli, isn't it?

gpulido commented 3 years ago

I don't know what could be happening. Could you try to execute the localapi.py standalone adding the "old" main:

if __name__ == '__main__':        
        m = Machine('192.168.90.9',  3000, 1)
        print(str(m))

If that works, please do the same but exectuting the init.py that uses the factory. It already has a main, but you will need to comment / uncomment some lines to test.

Mike-de-bike commented 3 years ago

@gpulido

  1. webserver error After some test, I realized, that with postman the api call went in an error. I had reset the webserver of the airzone controller.

  2. localapi.py After that localapi.py (with the attached main code) works. stefan@pizzabox:/usr/local/lib/python3.7/dist-packages/airzone$ python3 localapi.py Machine with id: 1Mode: OperationMode.COOLING Zones 1 2 3 4 5

  3. init.py After modifying the file from row number 20 it works:

     20 if __name__ == '__main__':
     21     #aido_args = {"has_louvres": False, "speed_as_per": True}
     22     #m = airzone_factory('modbus.local', 5020, 1, "aido", **aido_args)
     23     # m = airzone_factory('modbus.local', 5020, 1, "aido")
     24 
     25     #z = m.get_zones()[0]
     26     #print(m._machine_state)
     27     #print(z._zone_state)
     28     #print(bool(z.is_tacto_on()))
     29     #print(z.get_signal_temperature_value())
     30     #print(z.is_floor_active())
     31     #print(z.is_sleep_on())
     32     #print(z.is_automatic_mode())
     33     #print(z.get_zone_mode())
     34     #from airzone.protocol import state_value
     35 
     36     #print(state_value(z._zone_state, 0, 0, 1))
     37     #print(format(z._zone_state[0], '016b'))
     38 
     39     ## Localapi
     40     # Lines for Tests. Adapt argument ip address and system id (1 == standard).
     41     m = airzone_factory('192.168.90.9', 3000, 1, "localapi")
     42     print("Printing Post JSON data")
     43     print(m.machine_state)
     44     print("Number of zones: ", len(m.zones))
     45     print(m)
  1. init.py commenting in all after row 20. then restart of HA, then tried the integration of airzone with localapi - error: HA-ci_airzone-wizard-localapi-error
  2. ha log nothing in homeassistant.log

hope that helps

Mike-de-bike commented 3 years ago

@gpulido Output of: stefan@pizzabox:/usr/local/lib/python3.7/dist-packages/airzone$ sudo python3 __init__.py Printing Post JSON data [{'systemID': 1, 'zoneID': 1, 'name': 'Titus-1', 'on': 0, 'maxTemp': 30, 'minTemp': 18, 'setpoint': 23, 'roomTemp': 24.200001, 'mode': 2, 'coldStages': 1, 'coldStage': 1, 'heatStages': 1, 'heatStage': 1, 'humidity': 68, 'units': 0, 'errors': [], 'air_demand': 0, 'floor_demand': 0}, {'systemID': 1, 'zoneID': 2, 'name': 'Eltern-2', 'on': 0, 'maxTemp': 30, 'minTemp': 18, 'setpoint': 23, 'roomTemp': 24.200001, 'modes': [1, 4, 2, 3, 5], 'mode': 2, 'coldStages': 1, 'coldStage': 1, 'heatStages': 1, 'heatStage': 1, 'humidity': 67, 'units': 0, 'errors': [], 'air_demand': 0, 'floor_demand': 0}, {'systemID': 1, 'zoneID': 3, 'name': 'Thea-3', 'on': 0, 'maxTemp': 30, 'minTemp': 18, 'setpoint': 23, 'roomTemp': 25, 'mode': 2, 'coldStages': 1, 'coldStage': 1, 'heatStages': 1, 'heatStage': 1, 'humidity': 63, 'units': 0, 'errors': [], 'air_demand': 0, 'floor_demand': 0}, {'systemID': 1, 'zoneID': 4, 'name': 'Ella-4', 'on': 0, 'maxTemp': 30, 'minTemp': 18, 'setpoint': 23, 'roomTemp': 24.700001, 'mode': 2, 'coldStages': 1, 'coldStage': 1, 'heatStages': 1, 'heatStage': 1, 'humidity': 70, 'units': 0, 'errors': [], 'air_demand': 0, 'floor_demand': 0}, {'systemID': 1, 'zoneID': 5, 'name': 'Buero-5', 'on': 0, 'maxTemp': 30, 'minTemp': 18, 'setpoint': 23, 'roomTemp': 25.200001, 'mode': 2, 'coldStages': 1, 'coldStage': 1, 'heatStages': 1, 'heatStage': 1, 'humidity': 63, 'units': 0, 'errors': [], 'air_demand': 0, 'floor_demand': 0}] Number of zones: 5 Machine with id: 1Mode: OperationMode.COOLING Zones 1 2 3 4 5

gpulido commented 3 years ago

Hello @Mike-de-bike Thank you very much for testing. So after 1, 2 and 3, the conclusion is that the python-airzone 0.8.1 works although some improvements on the error handling could be made.

Now, I will take a look to the HA component to try find the problem on the configuration screen.

gpulido commented 3 years ago

@Mike-de-bike I have just updated the ha localapi with some changes to handle the I/O calls on the main thread. Please try it, it should at least allow you to get the devices on HA

Mike-de-bike commented 3 years ago

Hello @gpulido I have updated the homeassistant-airzone code, restarted HA -> integration is added successfully, no devices / entities are displayed. Good work so far! :-) HA-custom_integration-airzone-wizard-success HA-custom_integration_airzone

Mike-de-bike commented 3 years ago

@gpulido Here is the log of homeassistant for the wizard action: 2021-07-16 08:23:07 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration airzone which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant 2021-07-16 08:32:51 WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for airzone doing I/O at custom_components/airzone/climate.py, line 49: machine = airzone_factory(host, port, machine_id, system_class, **aidoo_args) 2021-07-16 08:32:51 ERROR (MainThread) [homeassistant.components.climate] Error while setting up airzone platform for climate Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/airzone/climate.py", line 73, in async_setup_entry devices = await hass.async_add_executor_job(get_devices(config)) File "/config/custom_components/airzone/climate.py", line 49, in get_devices machine = airzone_factory(host, port, machine_id, system_class, **aidoo_args) File "/usr/local/lib/python3.8/site-packages/airzone/__init__.py", line 8, in airzone_factory m = Machine(address, port, machineId) File "/usr/local/lib/python3.8/site-packages/airzone/localapi.py", line 51, in __init__ self.retrieve_system_data() File "/usr/local/lib/python3.8/site-packages/airzone/localapi.py", line 86, in retrieve_system_data response = requests.post(url=self._API_ENDPOINT, File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 119, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen httplib_response = self._make_request( File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 234, in request super(HTTPConnection, self).request(method, url, body=body, headers=headers) File "/usr/local/lib/python3.8/http/client.py", line 1252, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.8/http/client.py", line 1263, in _send_request self.putrequest(method, url, **skips) File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 214, in putrequest return _HTTPConnection.putrequest(self, method, url, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/util/async_.py", line 151, in protected_loop_func check_loop() File "/usr/src/homeassistant/homeassistant/util/async_.py", line 140, in check_loop raise RuntimeError( RuntimeError: I/O must be done in the executor; Useawait hass.async_add_executor_job()at custom_components/airzone/climate.py, line 49: machine = airzone_factory(host, port, machine_id, system_class, **aidoo_args)

gpulido commented 3 years ago

@Mike-de-bike I have moved the conversation to the Home assistant component issue, as now the 0.8.1 of python-airzone seems to work. https://github.com/gpulido/homeassistant-airzone/issues/11

I will close this issue, please feel free to reopen it if needed.