home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.47k stars 30.69k forks source link

LaMetric Time suddenly throws an error on HASS startup #78605

Closed bachya closed 2 years ago

bachya commented 2 years ago

The problem

I got the below stacktrace when I recently restarted HASS. Prior to this, the LaMetric integration had been working great. I can confirm that the device is connected to WiFi and nothing on the network has changed.

What version of Home Assistant Core has the issue?

core-2022.9.4

What was the last working version of Home Assistant Core?

core-2022.9.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

LaMetric

Link to integration documentation on our website

https://www.home-assistant.io/integrations/lametric/

Diagnostics information

I don't believe diagnostics have been developed for this integration.

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.lametric
Source: components/lametric/coordinator.py:34
Integration: LaMetric (documentation, issues)
First occurred: 4:01:26 PM (33 occurrences)
Last logged: 4:40:07 PM

Unexpected error fetching lametric data: 2 validation errors for Device wifi -> encryption field required (type=value_error.missing) wifi -> rssi none is not an allowed value (type=type_error.none.not_allowed)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/lametric/coordinator.py", line 34, in _async_update_data
    return await self.lametric.device()
  File "/usr/local/lib/python3.10/site-packages/demetriek/device.py", line 113, in device
    return Device.parse_obj(response)
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 342, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for Device
wifi -> encryption
  field required (type=value_error.missing)
wifi -> rssi
  none is not an allowed value (type=type_error.none.not_allowed)

Additional information

Since this integration doesn't support diagnostics, I patched the example script provided by python-demetriek to get device JSON before the exception is raised:

{
  "audio": {
    "volume": 100,
    "volume_limit": {
      "max": 100,
      "min": 0
    },
    "volume_range": {
      "max": 100,
      "min": 0
    }
  },
  "bluetooth": {
    "active": false,
    "address": "24:18:C6:19:6C:55",
    "available": true,
    "discoverable": true,
    "low_energy": {
      "active": true,
      "advertising": true,
      "connectable": true
    },
    "name": "LM2207",
    "pairable": true
  },
  "display": {
    "brightness": 100,
    "brightness_limit": {
      "max": 100,
      "min": 2
    },
    "brightness_mode": "auto",
    "brightness_range": {
      "max": 100,
      "min": 0
    },
    "height": 8,
    "screensaver": {
      "enabled": true,
      "modes": {
        "time_based": {
          "enabled": false
        },
        "when_dark": {
          "enabled": true
        }
      },
      "widget": "08b8eac21074f8f7e5a29f2855ba8060"
    },
    "type": "mixed",
    "width": 37
  },
  "id": "57880",
  "mode": "manual",
  "model": "LM 37X8",
  "name": "Basement Desk",
  "os_version": "2.2.4",
  "serial_number": "SA110405220700W00BS9",
  "wifi": {
    "active": true,
    "address": "24:18:C6:19:04:59",
    "available": true,
    "essid": "Phil?_IoT",
    "ip": "172.16.20.247",
    "mode": "dhcp",
    "netmask": "255.255.255.0"
  }
}
probot-home-assistant[bot] commented 2 years ago

lametric documentation lametric source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @robbiet480, @frenck, mind taking a look at this issue as it has been labeled with an integration (lametric) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

bachya commented 2 years ago

Based on the data returned by my device (in the description above), this looks like an upstream issue wherein python-demetriek expects wifi info to include a rssi field: https://github.com/frenck/python-demetriek/blob/b492f9d0edcd43624ed1066554dfdf49cb388344/src/demetriek/models.py#L73. Will post an issue there.