guerrerotook / securitas-direct-new-api

This repository contains the new securitas direct API that can be integrated in Home Assistant
Apache License 2.0
76 stars 30 forks source link

Status doesn't change #175

Closed javico88 closed 7 months ago

javico88 commented 9 months ago

I have connect my alarm panel to HA but whenever I try to change the status, in the UI panel or with service call, it doesn't change. I have tried to type the code and without it. The logs doesn't show anything. I have turned on DEBUG mode and it show this response:

dic 11 09:16:40 mx hass[3293]: 2023-12-11 09:16:40.040 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 3cd6d80be3604bbf, uuid 3cd6d80be3604bbf and idDeviceIndigital l dic 11 09:16:40 mx hass[3293]: 2023-12-11 09:16:40.285 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] -------------- Response-------------- dic 11 09:16:40 mx hass[3293]: 2023-12-11 09:16:40.288 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSSt atus":{"status":"D","timestampUpdate":"1702222568542"}}}

javico88 commented 9 months ago

Logs are also telling me that it didn't found a services.yaml for the Securitas integration. Is this file needed?

cantupaz commented 9 months ago

I'm getting pretty much the same problem. I'm using a fresh install of v2.4.0.4. I went through the setup process without problems (login, OTP, worked fine)

I am trying to arm the alarm. Nothing happens.

In the logs, I get an error "Unauthorized" As javico88, I get the services,yaml warning.

The securitas app doesn't show any updates either, but it does show regular status checks, so I guess HA is sending and receiving something.

If I can help test/debug something, please let me know.

2023-12-13 11:47:33.796 ERROR (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Unauthorized 2023-12-13 11:47:54.255 WARNING (SyncWorker_4) [homeassistant.helpers.service] Unable to find services.yaml for the securitas integration 2023-12-13 11:49:07.711 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 0b97d36e550f436e, uuid 0b97d36e550f436e and idDeviceIndigitall 2023-12-13 11:49:07.956 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] --------------Response-------------- 2023-12-13 11:49:07.956 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCheckAlarm":{"res":"OK","msg":"Su solicitud ha sido enviada","referenceId":"OWA___0912752720231213114907798__"}}}

2023-12-13 11:49:08.959 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 0b97d36e550f436e, uuid 0b97d36e550f436e and idDeviceIndigitall 2023-12-13 11:49:09.051 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] --------------Response-------------- 2023-12-13 11:49:09.051 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCheckAlarmStatus":{"res":"WAIT","msg":"Petición en proceso","status":null,"numinst":null,"protomResponse":null,"protomResponseDate":null}}}

2023-12-13 11:49:10.053 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 0b97d36e550f436e, uuid 0b97d36e550f436e and idDeviceIndigitall 2023-12-13 11:49:10.154 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] --------------Response-------------- 2023-12-13 11:49:10.154 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCheckAlarmStatus":{"res":"WAIT","msg":"Petición en proceso","status":null,"numinst":null,"protomResponse":null,"protomResponseDate":null}}}

2023-12-13 11:49:11.156 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 0b97d36e550f436e, uuid 0b97d36e550f436e and idDeviceIndigitall 2023-12-13 11:49:11.263 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] --------------Response-------------- 2023-12-13 11:49:11.263 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCheckAlarmStatus":{"res":"WAIT","msg":"Petición en proceso","status":null,"numinst":null,"protomResponse":null,"protomResponseDate":null}}}

2023-12-13 11:49:12.264 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 0b97d36e550f436e, uuid 0b97d36e550f436e and idDeviceIndigitall 2023-12-13 11:49:12.363 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] --------------Response-------------- 2023-12-13 11:49:12.363 DEBUG (MainThread) [custom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCheckAlarmStatus":{"res":"OK","msg":"Tu alarma está desconectada","status":"0","numinst":"4611831","protomResponse":"D","protomResponseDate":"2023-12-13 11:49:07.933"}}}

cantupaz commented 9 months ago

@javico88 hey, does your code start with 0? If so, try changing your code to something else.

javico88 commented 9 months ago

@javico88 hey, does your code start with 0? If so, try changing your code to something else.

Yes it is, well, I'm going to change and test

cantupaz commented 9 months ago

@guerrerotook Hi, I think you have a bug in the function below. Imagine if the code is "0000" (which was the case in my test). Converting the code string to an int gives 0 and then str(0) gives "0", so "0" will not match "0000"

Commenting the two lines below fixes the problem of this issue for me.

def check_code(self, code=None) -> bool:
    result: bool = False
    #        if isinstance(code, str):
    #            code = int(code)
    if (
        self.client.config.get(CONF_CODE, "") == ""
        or str(self.client.config.get(CONF_CODE, "")) == str(code)
        or self.client.config.get(CONF_CODE, None) is None
    ):
        result = True

    if not self.client.config_entry.data.get(CONF_ENABLE_CODE, True):
        result = True

    return result
javico88 commented 9 months ago

I have changed the code to something that doesn't start with 0. Now, I can disarm the alarm but I can't arm it. This is the log: dic 13 14:44:12 mx hass[1158]: 2023-12-13 14:44:12.268 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 2e294d83fb934705, uuid 2e294d83fb934705 and idDeviceIndigital l dic 13 14:44:12 mx hass[1158]: 2023-12-13 14:44:12.601 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] -------------- Response-------------- dic 13 14:44:12 mx hass[1158]: 2023-12-13 14:44:12.601 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCh eckAlarm":{"res":"OK","msg":"Su solicitud ha sido enviada","referenceId":"OWA ___2305905820231213154412401__"}}} dic 13 14:44:13 mx hass[1158]: 2023-12-13 14:44:13.604 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] Making request with device_id 2e294d83fb934705, uuid 2e294d83fb934705 and idDeviceIndigital l dic 13 14:44:13 mx hass[1158]: 2023-12-13 14:44:13.733 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] -------------- Response-------------- dic 13 14:44:13 mx hass[1158]: 2023-12-13 14:44:13.733 DEBUG (MainThread) [cu stom_components.securitas.securitas_direct_new_api.apimanager] {"data":{"xSCh eckAlarmStatus":{"res":"OK","msg":"Tu alarma está desconectada","status":"0", "numinst":"4896251","protomResponse":"D","protomResponseDate":"2023-12-13 15: 44:12.580"}}}

cantupaz commented 9 months ago

Weird. It worked for me. What version do you have? I have v2.4.0.4

Worst case, try updating to 2.4.0.4 and try copying this file to your installation (after updating to 2.4.0.4, otherwise I have no idea what could happen if you mix versions!):

https://github.com/cantupaz/securitas-direct-new-api/blob/5ac6421d1baf53c3cd0e018fb42e50d5c3f43197/custom_components/securitas/alarm_control_panel.py

javico88 commented 9 months ago

I have reinstalled the integration and it's finally working fine. It seems that it was not enough updating the code in the config. Thank you very much for your help

cantupaz commented 7 months ago

Newer versions of the integration fixed this. Closing as fixed.