Skip to content

feat & fix: better handling about the access rate#793

Open
zopanix wants to merge 4 commits intodvd-dev:mainfrom
zopanix:main
Open

feat & fix: better handling about the access rate#793
zopanix wants to merge 4 commits intodvd-dev:mainfrom
zopanix:main

Conversation

@zopanix
Copy link

@zopanix zopanix commented Dec 3, 2025

This contribution contains two changes:

  • fix: which changes the unit of the access fee from $/kwh to $/day
  • feat: which creates a entity that includes the daily access fee for a more accurate cost calculation

@ic-dev21
Copy link
Collaborator

ic-dev21 commented Dec 7, 2025

Je t'oublies pas je veux juste m'assurer que d'autres trucs marchent avant d'ajouter des feat.

@ic-dev21
Copy link
Collaborator

Salut @zopanix j'ai commencé à regarder ça un peu et pour là j'ai pas d'objections. Je me suis permis de le retravailler un peu.

J'aimerais que tu me mettes la fonction _handle_state_change async sinon on va avoir quelques soucis:

2026-01-25 08:50:01.034 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved (task: None):   File "/home/vscode/.local/ha-venv/bin/hass", line 10, in <module>
    sys.exit(main())
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/__main__.py", line 215, in main
    exit_code = runner.run(runtime_conf)
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/runner.py", line 289, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 712, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 683, 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 "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/helpers/event.py", line 360, in _async_dispatch_entity_id_event
    hass.async_run_hass_job(job, event)
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/core.py", line 905, in async_run_hass_job
    return self._async_add_hass_job(hassjob, *args, background=background)
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/core.py", line 733, in _async_add_hass_job
    task = self.loop.run_in_executor(None, hassjob.target, *args)
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 900, in run_in_executor
    return futures.wrap_future(
  File "/usr/local/lib/python3.13/asyncio/futures.py", line 414, in wrap_future
    new_future = loop.create_future()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 459, in create_future
    return futures.Future(loop=self)
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/workspaces/hilo/custom_components/hilo/sensor.py", line 1206, in _handle_state_change
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state
    report_non_thread_safe_operation("async_write_ha_state")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/helpers/frame.py", line 417, in report_non_thread_safe_operation
    report_usage(
    ~~~~~~~~~~~~^
        f"calls {what} from a thread other than the event loop, "
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
        custom_integration_behavior=ReportBehavior.ERROR,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/helpers/frame.py", line 218, in report_usage
    future.result()
    ~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/util/async_.py", line 67, in run_callback
    future.set_result(callback(*args))
                      ~~~~~~~~^^^^^^^
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/helpers/frame.py", line 266, in _report_usage
    _report_usage_integration_frame(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        hass,
        ^^^^^
    ...<4 lines>...
        integration_behavior is ReportBehavior.ERROR,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/vscode/.local/ha-venv/lib/python3.13/site-packages/homeassistant/helpers/frame.py", line 366, in _report_usage_integration_frame
    raise RuntimeError(
    ...<5 lines>...
    )
RuntimeError: Detected that custom integration 'hilo' calls async_write_ha_state from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#async_write_ha_state at custom_components/hilo/sensor.py, line 1206: self.async_write_ha_state(). Please create a bug report at https://github.com/dvd-dev/hilo/issues

Sinon merci d'utiliser du lazy formating sur le logging. C'est une meilleure pratique car le formatage se fait uniquement si la ligne de logging tourne, et non en tout temps.

christophe-scalepad and others added 4 commits January 25, 2026 09:24
This new rate also includes the access rate which provides you with a
more accurate total cost
Retiré un update de trop, lint check
Ajout d'un display precision dans le GUI, j'avais à peu près 17 décimales
@ic-dev21
Copy link
Collaborator

@zopanix il va manquer quelques doc strings pour que les linters soient content aussi. Si tu as un moment pour faire les petits correctifs ça va me faire plaisir de merger ça pour la prochaine version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants