cnstudio / Taipower-Bimonthly-Energy-Cost-homeassistant

Calculate Taipower (Taiwan Power Company) bi-monthly bill amount from kWh sensor on Home Assistant.
MIT License
68 stars 7 forks source link

警告訊息 2025.01 將停止支援 #25

Closed chehaochang closed 2 months ago

chehaochang commented 3 months ago

使用 2024.07 後出現警告

Detected code that calls async_forward_entry_setup for integration taipower_bimonthly_cost with title: TaiPower Energy Cost and entry_id: ***, during setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1. Please report this issue.

cnstudio commented 2 months ago

感謝您的回報, 請更新為 v0.53.1 版應該可以解決這個訊息出現.

如果您測試沒問題再請您關閉 (close) 這個 issue, 或約一周沒有任何回應的話也會關閉這個 issue.

chehaochang commented 2 months ago

使用 v0.53.1 會無法正常載入,系統會出現下面訊息

Error setting up entry TaiPower Energy Cost for taipower_bimonthly_cost
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/taipower_bimonthly_cost/__init__.py", line 27, in async_setup_entry
    hass.async_create_task(
  File "/usr/src/homeassistant/homeassistant/core.py", line 808, in async_create_task
    return self.async_create_task_internal(target, name, eager_start)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 830, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a coroutine was expected, got True

我自行將 init.py 中的程式碼

    for platform in PLATFORMS:
        hass.async_create_task(
            await hass.config_entries.async_forward_entry_setup(config_entry, platform)
        )

改為此段後,沒有出現錯誤及警告

    await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
cnstudio commented 2 months ago

感謝您的回報, 修改發行 v0.53.2 版先行修正此問題. :)

blade404386 commented 2 months ago

請問,在hacs裡面顯示是0.53.2版本,但是整合也還是顯示0.53.1版本,請問應該要如何更新呢? 也有重新下載過,依然顯示這樣

謝謝

cnstudio commented 2 months ago

不好意思, 請您更新 v0.53.3 版應該可以了 :)

blade404386 commented 2 months ago

感謝您的付出!!

不過更新0.53.3一樣還是出現錯誤 以下為錯誤日誌,感謝

記錄器: homeassistant.config_entries 來源: config_entries.py:604 首次發生: 下午11:19:00 (1 事件) 最後紀錄: 下午11:19:00

Error setting up entry TaiPower Energy Cost for taipower_bimonthly_cost Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/taipower_bimonthly_cost/init.py", line 27, in async_setup_entry hass.async_create_task( File "/usr/src/homeassistant/homeassistant/core.py", line 808, in async_create_task return self.async_create_task_internal(target, name, eager_start) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 830, in async_create_task_internal task = create_eagertask(target, name=name, loop=self.loop) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/async.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: a coroutine was expected, got None

記錄器: homeassistant.config_entries 來源: config_entries.py:604 首次發生: 下午11:19:00 (1 事件) 最後紀錄: 下午11:19:00

Error setting up entry TaiPower Energy Cost for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 130, in async_setup_entry return await component.async_setup_entry(entry) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 184, in async_setup_entry raise ValueError( ValueError: Config entry TaiPower Energy Cost (01J5X74X0HAE6QM1383WA39RK2) for taipower_bimonthly_cost.sensor has already been setup!

IMG_6799

cnstudio commented 2 months ago

請問更新到 v0.53.5 還有沒有錯誤訊息?

george0329 commented 2 months ago

請問更新到v0.53.5 還有沒有錯誤訊息?

感謝 v0.53.5已經正常了 螢幕擷取畫面 2024-08-24 035252

blade404386 commented 2 months ago

感謝您的不斷修正,現在在整合裡面已經都是正常了,但是實體都變成不可用且系統日誌裡面還是有錯誤,以下是系統日誌內容

謝謝

記錄器: homeassistant 來源: loader.py:1195 首次發生: 上午10:31:34 (2 事件) 最後紀錄: 上午10:31:34

Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2085, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1195, in async_get_platforms platforms[platform_name] = await future ^^^^^^^^^^^^ ModuleNotFoundError: No module named 'custom_components.taipower_bimonthly_cost.s'[](url)

cnstudio commented 2 months ago

因為新的 HASS 指令似乎重複執行會創建新的 sensors, 不知您有沒有機會嘗試反安裝, 刪除相關 sensors, 重啟 Home Assistant 後重新安裝一次試試?

blade404386 commented 2 months ago

您好, 我先在整合裝置裡面將產生的實體都先刪除,再來接著刪除Taipower,重新啟動 Home Assistant,重新安裝Taipower,重新啟動Home Assistant,然後新增整合,選擇對應的功耗表以及設定抄表日期。 但是不會顯示實體,以及系統日誌出現錯誤,以下為系統日誌訊息 謝謝

記錄器: homeassistant 來源: util/loop.py:200 首次發生: 下午1:31:39 (1 事件) 最後紀錄: 下午1:31:39

Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2085, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() [Previous line repeated 2 more times] File "/usr/src/homeassistant/homeassistant/loader.py", line 1147, in async_get_platforms await self.hass.async_add_import_executor_job( File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, *self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1090, in _load_platforms platform_name: self._load_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1264, in _load_platform cache[full_name] = self._import_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1296, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func return func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1324, in _find_and_load_unlocked ModuleNotFoundError: No module named 'custom_components.taipower_bimonthly_cost.s' FireShot Capture 008 - 設定 – Home Assistant - 192 168 50 22

cnstudio commented 2 months ago

不好意思, 請更新使用 v0.53.6 試試, 每次 HASS 改底層都會搞到很多開發者... :(

blade404386 commented 2 months ago

您好,真的很感謝您不斷的協助!!!!! 我先在整合裝置裡面將產生的實體都先刪除,再來接著刪除Taipower,重新啟動 Home Assistant,重新安裝Taipower,重新啟動Home Assistant,然後新增整合,選擇對應的功耗表以及設定抄表日期。 0.53.6依然顯示設定失敗,以下為系統日誌訊息 謝謝

記錄器: homeassistant.config_entries 來源: config_entries.py:604 首次發生: 下午2:01:51 (1 事件) 最後紀錄: 下午2:01:51

Error setting up entry TaiPower Energy Cost for taipower_bimonthly_cost Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/taipower_bimonthly_cost/init.py", line 28, in async_setup_entry await hass.config_entries.async_forward_entry_setups(config_entry, platform) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2085, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1116, in async_get_platforms if platform := self._get_platform_cached_or_raise(platform_name): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1207, in _get_platform_cached_or_raise raise ModuleNotFoundError( ModuleNotFoundError: Platform taipower_bimonthly_cost.s not found

記錄器: homeassistant.config_entries 來源: config_entries.py:604 首次發生: 下午2:01:40 (1 事件) 最後紀錄: 下午2:01:40

Error setting up entry TaiPower Energy Cost for taipower_bimonthly_cost Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/taipower_bimonthly_cost/init.py", line 28, in async_setup_entry await hass.config_entries.async_forward_entry_setups(config_entry, platform) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2085, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() [Previous line repeated 2 more times] File "/usr/src/homeassistant/homeassistant/loader.py", line 1147, in async_get_platforms await self.hass.async_add_import_executor_job( File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, *self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1090, in _load_platforms platform_name: self._load_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1264, in _load_platform cache[full_name] = self._import_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1296, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func return func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1324, in _find_and_load_unlocked ModuleNotFoundError: No module named 'custom_components.taipower_bimonthly_cost.s'

FireShot Capture 009 - 設定 – Home Assistant - 192 168 50 22

george0329 commented 2 months ago

不好意思, 請更新使用 v0.53.6 試試, 每次 HASS 改底層都會搞到很多開發者... :(

感謝你不斷的付出,因為有你的開發,我們才有這麼方便的集成使用。

cnstudio commented 2 months ago

也要感謝大家的使用及回饋 :) 讓我們先退回 v0.53.5 (.6 我這時標註為 beta), 請問如果刪除程式與各相關 sensors 後, 重新安裝一遍 0.53.5, 還會有實體不可用的狀況嗎?

因為本程式設計允許重複 reconfig 處理多個電表, 所以重複設定會產生多組計算, 使用同名的輸入源有可能導致實體衝突

blade404386 commented 2 months ago

您好, 刪除v0.53.6,重開Home assistant,重新安裝v0.53.5,重新新增整合,一樣會顯示無裝置與實體 系統日誌出現的錯誤訊息如下 謝謝

記錄器: homeassistant 來源: util/loop.py:200 首次發生: 下午3:00:15 (1 事件) 最後紀錄: 下午3:00:15

Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2085, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1177, in async_get_platforms import_future.result() [Previous line repeated 2 more times] File "/usr/src/homeassistant/homeassistant/loader.py", line 1147, in async_get_platforms await self.hass.async_add_import_executor_job( File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, *self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1090, in _load_platforms platform_name: self._load_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1264, in _load_platform cache[full_name] = self._import_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1296, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func return func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1324, in _find_and_load_unlocked ModuleNotFoundError: No module named 'custom_components.taipower_bimonthly_cost.s'

FireShot Capture 010 - 設定 – Home Assistant - 192 168 50 22

cnstudio commented 2 months ago

您好, 看您的 log 似乎都是 HASS 內部的問題, 請問您目前的 HASS 還有 HACS 是甚麼版本? 另外您在 UI 第一行輸入的是有用附錄一轉成 utility meter 的 sensor 嗎?

blade404386 commented 2 months ago

您好,UI第一個功耗表實體,與之前正常使用的版本是相同的實體,home assistant 版本是2024.8.2,hacs是2.0.0。

剛剛測試了v0.53.0,實體顯示正常,整合沒有顯示錯誤,系統日誌也沒有錯誤日誌。 (v0.53.3,下午測試也是不會顯示實體,有在上方留言貼上) IMG_6804 IMG_6805

shihkefa commented 2 months ago

這幾天更新的版本都有跟進,結果都不能用,退回v0.53.0版本都正常

cnstudio commented 2 months ago

請更新 v0.53.7 版應該可以解決所有問題, 我在測試環境測試都正常了, 請大家回報一下是否正常? 感謝大家辛苦的協助!! :)

blade404386 commented 2 months ago

您好,一切都正常了!! 感謝您的偉大成果!! 謝謝

Candyfox233 commented 2 months ago

實體的部分有正常運作了,謝謝!(不過我另一篇回報的問題還是存在)

cnstudio commented 2 months ago

感謝大家辛苦的測試與回報, 此案處理完畢關閉. :)