i8beef / HomeAutio.Mqtt.GoogleHome

MIT License
215 stars 29 forks source link

googleDevices.json - "id:" cannot begin with capital letters #72

Closed fightforlife closed 4 years ago

fightforlife commented 4 years ago

I just found a a little bug:

If the id of a googleDevice contains capital letters, it is not editable anymore after restarting Homeautio.

Maybe the Device "Id" field could check for capital letters or just add a small reminder.

`[17:14:48 INF] Loaded with configuration from: appsettings.json, /app/config/appsettings.Production.json

[17:14:49 INF] User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.

[17:14:49 INF] Starting IdentityServer4 version 2.3.2.0

[17:14:49 INF] Restored tokens from config/tokens.json

[17:14:49 INF] Using the default authentication scheme Cookies for IdentityServer

[17:14:50 INF] Loaded device configuration from config/googleDevices.json

[17:14:50 INF] Service start initiated

[17:14:50 INF] MQTT subscribing to the following topics: google/home/#, gateway/confirmation

[17:14:50 INF] Started

[17:14:50 INF] Service started successfully

Hosting environment: Production

Content root path: /app

Now listening on: http://[::]:5000

Application started. Press Ctrl+C to shut down.

[17:14:50 INF] MQTT Connection established

[17:14:50 INF] Connected.

[17:14:50 INF] ManagedMqttClient

[17:14:50 INF] MQTT message received for topic google/home/connected: 0

[17:14:50 INF] MQTT message received for topic google/home/connected: 2

[17:14:55 INF] Request starting HTTP/1.1 GET http://192.168.1.2:9035/GoogleDevice/Edit?deviceId=Computer  

[17:14:56 INF] Route matched with {action = "Edit", controller = "GoogleDevice"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Edit(System.String) on controller HomeAutio.Mqtt.GoogleHome.Controllers.GoogleDeviceController (HomeAutio.Mqtt.GoogleHome).

[17:14:56 INF] Authorization was successful.

[17:14:56 INF] Executing action method 
HomeAutio.Mqtt.GoogleHome.Controllers.GoogleDeviceController.Edit (HomeAutio.Mqtt.GoogleHome) - Validation state: Valid

[17:14:56 INF] Executed action method HomeAutio.Mqtt.GoogleHome.Controllers.GoogleDeviceController.Edit (HomeAutio.Mqtt.GoogleHome), returned result Microsoft.AspNetCore.Mvc.NotFoundResult in 4.3716ms.

[17:14:56 INF] Executing HttpStatusCodeResult, setting HTTP status code 404

[17:14:56 INF] Executed action HomeAutio.Mqtt.GoogleHome.Controllers.GoogleDeviceController.Edit (HomeAutio.Mqtt.GoogleHome) in 176.404ms

[17:14:56 INF] Request finished in 735.7062ms 404 `
i8beef commented 4 years ago

I don't think that's your issue... I have plenty of devices in my setup with mixed casings. By chance did you accidentally catch a WHITESPACE character in the name?

i8beef commented 4 years ago

Note, you can look at your googleDevices.json file to see what was captured in the name (and if its whitespace getting captured, then you can remove it there, restart, and you should be back to editable).

fightforlife commented 4 years ago

I just tried it again:

This is working: http://192.168.1.2:9035/GoogleDevice/Edit?deviceId=computer 200 - found

{
  "computer": {
    "id": "computer",
    "type": "action.devices.types.OUTLET",
    "disabled": false,
    "willReportState": true,
    "roomHint": "Wohnzimmer",
    "name": {
      "defaultNames": [],
      "name": "Computer",
      "nicknames": []
    },
    "deviceInfo": null,
    "traits": [
      {
        "trait": "action.devices.traits.OnOff",
        "attributes": null,
        "commands": {
          "action.devices.commands.OnOff": {
            "on": "gateway/send/433"
          }
        },
        "state": {
          "on": {
            "topic": "gateway/confirmation",
            "googleType": "bool",
            "valueMap": [
              {
                "mqtt": "1135889,300,1",
                "type": "value",
                "google": true
              },
              {
                "mqtt": "1135892,300,1",
                "type": "value",
                "google": false
              }
            ]
          }
        }
      }
    ],
    "customData": null
  }
}

This is not working (capitel in id field): http://192.168.1.2:9035/GoogleDevice/Edit?deviceId=Computer 404 not found

{
  "computer": {
    "id": "Computer",
    "type": "action.devices.types.OUTLET",
    "disabled": false,
    "willReportState": true,
    "roomHint": "Wohnzimmer",
    "name": {
      "defaultNames": [],
      "name": "Computer",
      "nicknames": []
    },
    "deviceInfo": null,
    "traits": [
      {
        "trait": "action.devices.traits.OnOff",
        "attributes": null,
        "commands": {
          "action.devices.commands.OnOff": {
            "on": "gateway/send/433"
          }
        },
        "state": {
          "on": {
            "topic": "gateway/confirmation",
            "googleType": "bool",
            "valueMap": [
              {
                "mqtt": "1135889,300,1",
                "type": "value",
                "google": true
              },
              {
                "mqtt": "1135892,300,1",
                "type": "value",
                "google": false
              }
            ]
          }
        }
      }
    ],
    "customData": null
  }
}
i8beef commented 4 years ago

How did you get it into that state? The issue is that "id" and the actual key should always match.

I.e., should be:

{
  "Computer": {
    "id": "Computer",
i8beef commented 4 years ago

ok THAT looks like a bug. I think when you change the id after initial creation, it updates the id but not the device repository key. Ill add a todo item for this.

In the mean time, you should be able to correct by editing the googleDevices.json, making them match again, and restarting the app.

fightforlife commented 4 years ago

It is also present at inital creation of a device:

Entering a device like this: 2020-03-27 19_50_06-Window

Results in this: 2020-03-27 19_50_45-

Which results in a 404 because the id is capital and and the key is not.

i8beef commented 4 years ago

Ah. TWO issues. Ill have to consider this. THAT'S a serialization issue. Just don't start the device with a capital. Capitals anywhere else in the name will be kosher.