OpenWonderLabs / SwitchBotAPI

SwitchBot Open API Documents
853 stars 70 forks source link

Webhooks not sent for Floor Cleaning Robot S10 #321

Open abx360 opened 3 months ago

abx360 commented 3 months ago

Analysis

Active polling is correctly working for the S10 Vacuum, but the API is not sending updates through webhooks.

Expected Behavior

If a webhook is configured in my own API account, I should receive active updates when something is changing in the device status.

Steps To Reproduce

  1. Test that the webhook is correctly configured, asking the API the webhook details with the queryDetails command: curl -H "Content-Type: application/json" -H "Authorization":"XXmykeyXX" -X POST https://api.switch-bot.com/v1.1/webhook/queryWebhook -d '{"action":"queryDetails", "urls":"https://sbmqtt. xxmysitexx.it/webhook"}' The following reply confirms the good setup: {"statusCode":100,"body":[{"deviceList":"ALL","createTime":1720015356692,"url":"https://sbmqtt.xxmysitexx.it/webhook","enable":true,"lastUpdateTime":1720015356692}],"message":"success"}

  2. Test the device configuration, querying the device list with the GET /v1.1/devices command: curl -H "Content-Type: application/json" -H "Authorization: XXmykeyXX" -X GET https://api.switch-bot.com/v1.1/devices The following reply confirms the good setup: {"statusCode":100,"body":{"deviceList":[{"deviceId":"XXsnXX","deviceName":"Signor Robot IV","deviceType":"Robot Vacuum Cleaner S10","enableCloudService":true,"hubDeviceId":""}],"infraredRemoteList":[]},"message":"success"}

  3. Verify that my webserver, reverse proxy and firewall are correctly configured emulating a webhook from the SwitchBot API: curl -H "Content-Type: application/json" -X POST https://sbmqtt.XXmysiteXX.it/webhook -d '{"eventType":"changeReport","eventVersion":"1","context":{"deviceMac":"XXsnXX","deviceType":"WoSweeperOrigin","workingStatus":"ChargeDone","onlineStatus":"online","battery":79,"waterBaseBattery":100,"taskType":"standBy","timeOfSample":1715158038876}}' Check the server logs for incoming webhooks. The following log shows the dummy webhook is correctly received: switchbotmqtt | 16:03:50 info: SwitchBotMqttApp.Controllers.WebhookController[0] {"eventType":"changeReport","eventVersion":"1","context":{"deviceMac":"XXsnXX","deviceType":"WoSweeperOrigin","workingStatus":"ChargeDone","onlineStatus":"online","battery":79,"waterBaseBattery":100,"taskType":"standBy","timeOfSample":1715158038876}}

Logs

No incoming connection, so no log 😉

Configuration

API webhook configuration:
`{"statusCode":100,"body":[{"deviceList":"ALL","createTime":1720015356692,"url":"https://sbmqtt.xxmysitexx.it/webhook","enable":true,"lastUpdateTime":1720015356692}],"message":"success"}`

API device shown:
`{"statusCode":100,"body":{"deviceList":[{"deviceId":"XXsnXX","deviceName":"Signor Robot IV","deviceType":"Robot Vacuum Cleaner S10","enableCloudService":true,"hubDeviceId":""}],"infraredRemoteList":[]},"message":"success"}`

Environment

Additional Context

I don't have any other Switchbot device to try.

hsakoh commented 1 month ago

Based on feedback from a Home Assistant add-on user, it was found that the webhook is now being sent, but it differs from the specification. (Inside and outside of context, and only partial state values.)

expect:

{
    "eventType": "changeReport",
    "eventVersion": "1",
    "context": {
        "deviceType": "Robot Vacuum Cleaner S10",
        "deviceMac": DEVICE_MAC_ADDR,
        "workingStatus":"StandBy",
        "onlineStatus": "online",
        "battery": 100,// 0-100
        "waterBaseBattery": 100,
        "taskType": "explore",
        "timeOfSample": 123456789
    }
}

actual:

{
  "eventType": "changeReport",
  "eventVersion": "1",
  "context": {
    "deviceType": "Robot Vacuum Cleaner S10",
    "deviceMac": "XXXXXXX",
    "timeOfSample": 1725002665366
  },
  "onlineStatus": "online",
  "taskType": "cleanAll"
}

@SwitchBot @SwitchBot-Wonderlabs @Minsheng Could you please either update the documentation or ensure that the webhook is sent as described in the documentation?