Somfy-Developer / Somfy-TaHoma-Developer-Mode

A collection of requests to use a local API with Somfy TaHoma gateways
147 stars 12 forks source link

setup/devices/{deviceURL}/states not working #7

Closed AdyRock closed 2 years ago

AdyRock commented 2 years ago

I'm getting error 400 when posting to: 'https://gateway-xxxx-xxxx-xxxx.local:8443/enduser-mobile-web/1/enduserAPI//setup/devices/io%3A%2F%2Fxxx-xxxx-xxx%2Fxxxxxxx/states'

Obviously I have replaced my personal information with x's

However, 'https://gateway-xxxx-xxxx-xxxx.local:8443/enduser-mobile-web/1/enduserAPI//setup/devices/io%3A%2F%2Fxxx-xxxx-xxx%2Fxxxxxxx' Is working.

I can also control the same device.

vhenriet-sfy commented 2 years ago

Could you give us more details on the http query and answer? (GET/POST, headers, response body, ...)

AdyRock commented 2 years ago

I'm using GET, no body, headers are { 'content-type': 'application/json', Authorization: Bearer ${bearer}, 'User-Agent': 'homey' }

I'm not seeing a response body, just the error code 400.

As I mentioned, if I just remove the /states from the end of the URL then I get valid data returned that includes the states.

vhenriet-sfy commented 2 years ago

I did not find a way to reproduce your issue.

Could you try a call using curl and send me full verbose log?

AdyRock commented 2 years ago

Response headers:

content-type: application/json access-control-allow-origin: * access-control-allow-headers: Authorization content-length: 59 date: Fri, 08 Apr 2022 15:56:49 GMT server: KizOs

Response body:

{ "error": "Unknown object.", "errorCode": "UNSPECIFIED_ERROR" }

AdyRock commented 2 years ago

If it is any help this is the response to the apiVersion request: { "message": "Local API Version", "stack": { "protocolVersion": "2022.1.4-26" }

iMicknl commented 2 years ago

I can reproduce. Endpoint GET /enduser-mobile-web/1/enduserAPI/setup/devices/{device_url}/states does not exist. (Unknown object error). Same for /setup/devices/{deviceURL}/states/{name}.

Perhaps the same issue as #4? It seems that some endpoints are not present (yet). They are all mentioned here: https://somfy-developer.github.io/Somfy-TaHoma-Developer-Mode/.

Out of interest, @AdyRock, what is your usecase for calling the /states/ endpoint? We don't use this in the Home Assistant integration, we only pull our states from the event listener.

AdyRock commented 2 years ago

I use it at start up and when adding a device to initialise the state of each device. Also some users don't poll the events so they just fetch the current state when required. I think they are still nervous from the message that was sent out last year about excessive usage. Since I took over the app I changed it from getting all devices every 10 seconds to getting the events every 30 seconds, so polling should not be a problem anymore but some users are still unsure.

an-mediola commented 2 years ago

@vhenriet-sfy is it possible to guide me too?

What should be the deviceUrl in get states request?

My Device :

{
        "deviceURL": "io://1224-5722-0308/4792196",
        "available": true,
        "synced": true,
        "type": 1,
        "states": [
            {
                "type": 3,
                "name": "core:StatusState",
                "value": "available"
            },
            {
                "type": 3,
                "name": "core:DiscreteRSSILevelState",
                "value": "good"
            },
            {
                "type": 1,
                "name": "core:RSSILevelState",
                "value": 100
            },
            {
                "type": 1,
                "name": "core:ClosureState",
                "value": 45
            },
            {
                "type": 3,
                "name": "core:OpenClosedState",
                "value": "open"
            },
            {
                "type": 1,
                "name": "core:TargetClosureState",
                "value": 45
            },
            {
                "type": 6,
                "name": "core:MovingState",
                "value": false
            },
            {
                "type": 3,
                "name": "core:NameState",
                "value": "OXIMO io"
            },
            {
                "type": 1,
                "name": "core:Memorized1PositionState",
                "value": 86
            }
        ],
        "label": "OXIMO io",
        "subsystemId": 0,
        "attributes": [
            {
                "type": 3,
                "name": "core:Manufacturer",
                "value": "Somfy"
            }
        ],
        "enabled": true,
        "controllableName": "io:RollerShutterGenericIOComponent",
        "definition": {
            "states": [
                {
                    "name": "core:DiscreteRSSILevelState"
                },
                {
                    "name": "core:RSSILevelState"
                },
                {
                    "name": "core:NameState"
                },
                {
                    "name": "core:Memorized1PositionState"
                },
                {
                    "name": "core:TargetClosureState"
                },
                {
                    "name": "core:SecuredPositionState"
                },
                {
                    "name": "core:ClosureState"
                },
                {
                    "name": "core:OpenClosedState"
                },
                {
                    "name": "core:MovingState"
                },
                {
                    "name": "core:ManufacturerSettingsState"
                },
                {
                    "name": "core:AdditionalStatusState"
                },
                {
                    "name": "core:StatusState"
                }
            ],
            "widgetName": "PositionableRollerShutter",
            "type": "ACTUATOR",
            "commands": [
                {
                    "commandName": "stop",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "setDeployment",
                    "paramsSig": "p1"
                },
                {
                    "nparams": 1,
                    "commandName": "delayedStopIdentify",
                    "paramsSig": "p1"
                },
                {
                    "nparams": 2,
                    "commandName": "runManufacturerSettingsCommand",
                    "paramsSig": "p1,p2"
                },
                {
                    "commandName": "refreshMemorized1Position",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "setClosure",
                    "paramsSig": "p1"
                },
                {
                    "commandName": "unpairAllOneWayControllers",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "setConfigState",
                    "paramsSig": "p1"
                },
                {
                    "nparams": 1,
                    "commandName": "pairOneWayController",
                    "paramsSig": "p1,*p2"
                },
                {
                    "commandName": "unpairAllOneWayControllersAndDeleteNode",
                    "nparams": 0
                },
                {
                    "commandName": "sendIOKey",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "wink",
                    "paramsSig": "p1"
                },
                {
                    "commandName": "startIdentify",
                    "nparams": 0
                },
                {
                    "commandName": "stopIdentify",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "unpairOneWayController",
                    "paramsSig": "p1,*p2"
                },
                {
                    "nparams": 1,
                    "commandName": "setSecuredPosition",
                    "paramsSig": "p1"
                },
                {
                    "commandName": "keepOneWayControllersAndDeleteNode",
                    "nparams": 0
                },
                {
                    "commandName": "my",
                    "nparams": 0
                },
                {
                    "commandName": "up",
                    "nparams": 0
                },
                {
                    "commandName": "open",
                    "nparams": 0
                },
                {
                    "commandName": "close",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "setName",
                    "paramsSig": "p1"
                },
                {
                    "commandName": "identify",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "setPosition",
                    "paramsSig": "p1"
                },
                {
                    "commandName": "getName",
                    "nparams": 0
                },
                {
                    "commandName": "down",
                    "nparams": 0
                },
                {
                    "nparams": 1,
                    "commandName": "advancedRefresh",
                    "paramsSig": "p1"
                },
                {
                    "nparams": 1,
                    "commandName": "setMemorized1Position",
                    "paramsSig": "p1"
                }
            ],
            "uiClass": "RollerShutter"
        }
    }

None of the following work:

curl --location --request GET 'https://gateway-1224-5722-0308.local:8443/enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F1224-5722-0308%2F4792196/states' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer 626bd68b7cd25dccabfe'
curl --location --request GET 'https://gateway-1224-5722-0308.local:8443/enduser-mobile-web/1/enduserAPI/setup/devices/1224-5722-0308%2F4792196/states' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer 626bd68b7cd25dccabfe'
curl --location --request GET 'https://gateway-1224-5722-0308.local:8443/enduser-mobile-web/1/enduserAPI/setup/devices/4792196/states' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer 626bd68b7cd25dccabfe'
iMicknl commented 2 years ago

Did you try to url encode this? So io://1224-5722-0308/4792196 would be io%3A%2F%2F1224-5722-0308%2F4792196.

an-mediola commented 2 years ago

Did you try to url encode this? So io://1224-5722-0308/4792196 would be io%3A%2F%2F1224-5722-0308%2F4792196.

@iMicknl Yes, I've tried all the possible ways. I've posted all of them in my comment. Do you have any suggestion?

iMicknl commented 2 years ago

Sorry, I missed that one in your statement, however that should be the format. As you can read in my and @AdyRock response above, this endpoint is currently missing in the deployment, thus that's why it won't work.

You can try this endpoint on the tahomalink.com endpoint to try it until Somfy fixes the deployment.

vhenriet-sfy commented 2 years ago

The deviceURL parameter, like all other url parameters have to be url encoded. ( rfc3986 )

So io%3A%2F%2F1224-5722-0308%2F4792196 is the proper way.

I'm still not able to reproduce the issue.

The following curl command produce the expected result:

curl -v -H "Authorization: Bearer 01234567890123456789"  --request GET https://gateway-2001-0001-1891.local:8443/enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F2001-0001-1891%2F15308991/states
> GET /enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F2001-0001-1891%2F15308991/states HTTP/1.1
> Host: gateway-2001-0001-1891.local:8443
> User-Agent: curl/7.79.1
> Accept: */*
> Authorization: Bearer 01234567890123456789
> 

< HTTP/1.1 200 OK
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Authorization
< Content-Length: 588
< Date: Fri, 29 Apr 2022 13:23:55 GMT
< Server: KizOs
< 

[{"type":3,"name":"core:StatusState","value":"available"},{"type":3,"name":"core:DiscreteRSSILevelState","value":"good"},{"type":1,"name":"core:RSSILevelState","value":100},{"type":11,"name":"core:ManufacturerSettingsState","value":{"current_position":20374}},{"type":1,"name":"core:ClosureState","value":40},{"type":3,"name":"core:OpenClosedState","value":"open"},{"type":1,"name":"core:TargetClosureState","value":40},{"type":6,"name":"core:MovingState","value":false},{"type":3,"name":"core:NameState","value":"Volet salon"},{"type":1,"name":"core:Memorized1PositionState","value":91}]
an-mediola commented 2 years ago

@vhenriet-sfy I think I had not provide the wrong request. But I just wanted to show that I've tested all possible ways. It seems that you are working on prototype box or something that we do not have access to. Does the following have a problem?

curl -v -k -H  "Authorization: Bearer 626bd68b7cd25dccabfe"  --request GET https://gateway-1224-5722-0308.local:8443/enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F1224-5722-0308%2F4792196/states
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying fe80::fa81:1aff:fe57:67eb...
* TCP_NODELAY set
*   Trying 192.168.55.91...
* TCP_NODELAY set
* Connected to gateway-1224-5722-0308.local (192.168.55.91) port 8443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: O=Overkiz; OU=Overkiz Device Server; CN=1224-5722-0308.local
*  start date: Sep  6 17:40:27 2019 GMT
*  expire date: Sep  3 17:40:27 2029 GMT
*  issuer: C=FR; O=Overkiz; OU=Overkiz Device Server CA; CN=Overkiz Device Server CA
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> GET /enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F1224-5722-0308%2F4792196/states HTTP/1.1
> Host: gateway-1224-5722-0308.local:8443
> User-Agent: curl/7.64.1
> Accept: */*
> Authorization: Bearer 626bd68b7cd25dccabfe
> 
< HTTP/1.1 400 Bad Request
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Authorization
< Content-Length: 59
< Date: Fri, 29 Apr 2022 13:45:46 GMT
< Server: KizOs
< 
* Connection #0 to host gateway-1224-5722-0308.local left intact
{"error":"Unknown object.","errorCode":"UNSPECIFIED_ERROR"}* Closing connection 0
vhenriet-sfy commented 2 years ago

Could you confirm that you got no issue with the endpoint /enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F1224-5722-0308%2F4792196 and give me the response body?

an-mediola commented 2 years ago

@vhenriet-sfy

curl --location --request GET 'https://gateway-1224-5722-0308.local:8443/enduser-mobile-web/1/enduserAPI/setup/devices/io%3A%2F%2F1224-5722-0308%2F4792196' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer 626bd68b7cd25dccabfe'

response :

{
    "deviceURL": "io://1224-5722-0308/4792196",
    "available": true,
    "synced": true,
    "type": 1,
    "states": [
        {
            "type": 3,
            "name": "core:StatusState",
            "value": "available"
        },
        {
            "type": 3,
            "name": "core:DiscreteRSSILevelState",
            "value": "good"
        },
        {
            "type": 1,
            "name": "core:RSSILevelState",
            "value": 100
        },
        {
            "type": 1,
            "name": "core:ClosureState",
            "value": 35
        },
        {
            "type": 3,
            "name": "core:OpenClosedState",
            "value": "open"
        },
        {
            "type": 1,
            "name": "core:TargetClosureState",
            "value": 35
        },
        {
            "type": 6,
            "name": "core:MovingState",
            "value": false
        },
        {
            "type": 3,
            "name": "core:NameState",
            "value": "OXIMO io"
        },
        {
            "type": 1,
            "name": "core:Memorized1PositionState",
            "value": 86
        }
    ],
    "label": "OXIMO io",
    "subsystemId": 0,
    "attributes": [
        {
            "type": 3,
            "name": "core:Manufacturer",
            "value": "Somfy"
        }
    ],
    "enabled": true,
    "controllableName": "io:RollerShutterGenericIOComponent",
    "definition": {
        "states": [
            {
                "name": "core:DiscreteRSSILevelState"
            },
            {
                "name": "core:RSSILevelState"
            },
            {
                "name": "core:NameState"
            },
            {
                "name": "core:Memorized1PositionState"
            },
            {
                "name": "core:TargetClosureState"
            },
            {
                "name": "core:SecuredPositionState"
            },
            {
                "name": "core:ClosureState"
            },
            {
                "name": "core:OpenClosedState"
            },
            {
                "name": "core:MovingState"
            },
            {
                "name": "core:ManufacturerSettingsState"
            },
            {
                "name": "core:AdditionalStatusState"
            },
            {
                "name": "core:StatusState"
            }
        ],
        "widgetName": "PositionableRollerShutter",
        "type": "ACTUATOR",
        "commands": [
            {
                "commandName": "stop",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "setDeployment",
                "paramsSig": "p1"
            },
            {
                "nparams": 1,
                "commandName": "delayedStopIdentify",
                "paramsSig": "p1"
            },
            {
                "nparams": 2,
                "commandName": "runManufacturerSettingsCommand",
                "paramsSig": "p1,p2"
            },
            {
                "commandName": "refreshMemorized1Position",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "setClosure",
                "paramsSig": "p1"
            },
            {
                "commandName": "unpairAllOneWayControllers",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "setConfigState",
                "paramsSig": "p1"
            },
            {
                "nparams": 1,
                "commandName": "pairOneWayController",
                "paramsSig": "p1,*p2"
            },
            {
                "commandName": "unpairAllOneWayControllersAndDeleteNode",
                "nparams": 0
            },
            {
                "commandName": "sendIOKey",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "wink",
                "paramsSig": "p1"
            },
            {
                "commandName": "startIdentify",
                "nparams": 0
            },
            {
                "commandName": "stopIdentify",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "unpairOneWayController",
                "paramsSig": "p1,*p2"
            },
            {
                "nparams": 1,
                "commandName": "setSecuredPosition",
                "paramsSig": "p1"
            },
            {
                "commandName": "keepOneWayControllersAndDeleteNode",
                "nparams": 0
            },
            {
                "commandName": "my",
                "nparams": 0
            },
            {
                "commandName": "up",
                "nparams": 0
            },
            {
                "commandName": "open",
                "nparams": 0
            },
            {
                "commandName": "close",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "setName",
                "paramsSig": "p1"
            },
            {
                "commandName": "identify",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "setPosition",
                "paramsSig": "p1"
            },
            {
                "commandName": "getName",
                "nparams": 0
            },
            {
                "commandName": "down",
                "nparams": 0
            },
            {
                "nparams": 1,
                "commandName": "advancedRefresh",
                "paramsSig": "p1"
            },
            {
                "nparams": 1,
                "commandName": "setMemorized1Position",
                "paramsSig": "p1"
            }
        ],
        "uiClass": "RollerShutter"
    }
}
vhenriet-sfy commented 2 years ago

Fix available with api version > 2022.4