Skip to content

TypeError in debug logging with auto mode disabled #44

Description

@anssih

I'm seeing the following on a PID controller with Auto mode set to Off (i.e. from startup). The output is still None as the PID has not ever started, but the code tries to format it as float.

--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/logging/handlers.py", line 1509, in emit
    self.enqueue(self.prepare(record))
                 ~~~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.13/logging/handlers.py", line 1491, in prepare
    msg = self.format(record)
  File "/usr/local/lib/python3.13/logging/__init__.py", line 998, in format
    return fmt.format(record)
           ~~~~~~~~~~^^^^^^^^
  File "/usr/local/lib/python3.13/logging/__init__.py", line 711, in format
    record.message = record.getMessage()
                     ~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/logging/__init__.py", line 400, in getMessage
    msg = msg % self.args
          ~~~~^~~~~~~~~~~
TypeError: must be real number, not NoneType
Call stack:
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 706, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 677, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2034, in _run_once
    handle._run()
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 254, in __wrap_handle_refresh_interval
    self.config_entry.async_create_background_task(
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1318, in async_create_background_task
    task = hass.async_create_background_task(target, name, eager_start)
  File "/usr/src/homeassistant/homeassistant/core.py", line 862, in async_create_background_task
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 270, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 382, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/simple_pid_controller/coordinator.py", line 32, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/simple_pid_controller/sensor.py", line 79, in update_pid
    _LOGGER.debug(
  File "/usr/local/lib/python3.13/logging/__init__.py", line 1507, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/local/lib/python3.13/logging/__init__.py", line 1664, in _log
    self.handle(record)
  File "/usr/local/lib/python3.13/logging/__init__.py", line 1680, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.13/logging/__init__.py", line 1736, in callHandlers
    hdlr.handle(record)
  File "/usr/src/homeassistant/homeassistant/util/logging.py", line 113, in handle
    self.emit(record)
Message: 'PID input=%.2f setpoint=%.2f kp=%.2f ki=%.2f kd=%.2f => output=%.2f [P=%.2f, I=%.2f, D=%.2f]'
Arguments: (23.21, 20.0, 0.05, 0.01, 0.5, None, -0.16050000000000006, 0.18, 0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working as expected

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions