core icon indicating copy to clipboard operation
core copied to clipboard

Glances - Update for sensor <disk> fails: UnboundLocalError: local variable 'disk' referenced before assignment

Open thomasgermain opened this issue 2 years ago • 1 comments

The problem

Some glances entities don't update and gives error in the logs.

What version of Home Assistant Core has the issue?

2022.11.x

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

glances

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.helpers.entity
Source: components/glances/sensor.py:377
First occurred: 15:36:37 (35 occurrences)
Last logged: 15:42:21

Update for sensor.home_server_snap_core18_2560_free fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 527, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 722, in async_device_update
    raise exc
  File "/usr/src/homeassistant/homeassistant/components/glances/sensor.py", line 377, in async_update
    self._attr_native_value = round(disk["free"] / 1024**3, 1)
UnboundLocalError: local variable 'disk' referenced before assignment

Additional information

It sounds like it happens when a "mnt_point" has been changed/removed.

I guess a fix like that should be sufficient ? (I submit a PR within next week) Or maybe it means the entity should be removed ?

            disk = None
            for var in value["fs"]:
                if var["mnt_point"] == self._sensor_name_prefix:
                    disk = var
                    break
            if disk:
                [...]

thomasgermain avatar Nov 06 '22 14:11 thomasgermain

Hey there @engrbm87, mind taking a look at this issue as it has been labeled with an integration (glances) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of glances can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign glances Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


glances documentation glances source (message by IssueLinks)

home-assistant[bot] avatar Nov 06 '22 14:11 home-assistant[bot]