BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
535 stars 50 forks source link

Invalid currency code #729

Open Evaske opened 5 months ago

Evaske commented 5 months ago

Describe the bug

Seeing a lot of console errors for the GBP/kWh unit for current/next rate etc.

format_number.ts:73 RangeError: Invalid currency code : GBP/kWh

Reproduction steps

Just open the console and be on the Electricity entity page

Expected behaviour

No console error

Tariff Code

E-1R-AGILE-23-12-06-H

Integration Version

v10.0.3

Home Assistant Version

2024.1.5

Fresh Install?

Fresh install

Home Assistant Logs

No logs related to the error

Confirmation

BottlecapDave commented 5 months ago

Hello. I have not seen this before nor had others reported this issue before. The entity reports a unit of measurement similar to other native integrations, and has done for a while. Are you using the entity with a template sensor or another custom component? Have you changed anything around the entity from its default settings?

github-actions[bot] commented 4 months ago

This issue has become stale because it has been open for 30 days with no activity. If you still think it's an issue, please respond soon.

github-actions[bot] commented 3 months ago

This issue has been closed because it has been inactive for 14 days since being marked as stale. This is done to help keep on top of active issues. If you still think it's an issue, please respond to this issue

whatdaybob commented 1 month ago

Sorry, i too am receiving this error.

format_number.ts:73 RangeError: Invalid currency code : GBP/kWh
at new NumberFormat (<anonymous>)
at c (format_number.ts:66:14)
at m (compute_state_display.ts:93:16)
at f (compute_state_display.ts:52:10)
at Object.formatEntityState (entity-state.ts:38:7)
at F.value (hui-sensor-entity-row.ts:81:25)
at F.update (lit-element.ts:160:24)
at F.performUpdate (reactive-element.ts:1329:14)

appears to be in /src/common/number/format_number.ts in the below part with Intl.NumberFormat trying to check its a valid ISO 4217 currency code.

    try {
      return new Intl.NumberFormat(
        locale,
        getDefaultFormatOptions(num, options)
      ).format(Number(num));
    } catch (err: any) {
      // Don't fail when using "TEST" language
      // eslint-disable-next-line no-console
      console.error(err);
      return new Intl.NumberFormat(
        undefined,
        getDefaultFormatOptions(num, options)
      ).format(Number(num));
    }

Unsure what you can do on this one that isnt a breaking change to resolve if it does become a bigger issues.

BottlecapDave commented 1 month ago

As previously mentioned, there's very little to go on with this issue. Have you changed anything in the standard entities that might cause this to happen (e.g. change formatting via the UI)? As previously mentioned it uses a unit of measurement in a similar way to other native integrations so not sure what's causing this failure.

whatdaybob commented 1 month ago

No, it’s setup exactly as the documentation says and this is on the default home assistant Lovelace generated dashboard.

On 25 May 2024, at 10:37, David Kendall @.***> wrote:



As previously mentioned, there's very little to go on with this issue. Have you changed anything in the standard entities that might cause this to happen (e.g. change formatting via the UI)? As previously mentioned it uses a unit of measurement in a similar way to other native integrations so not sure what's causing this failure.

— Reply to this email directly, view it on GitHubhttps://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/729#issuecomment-2131163439, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABLJ34N47QZMWE26KF455K3ZEBLWHAVCNFSM6AAAAABCOOYBRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZRGE3DGNBTHE. You are receiving this because you commented.Message ID: @.***>

BottlecapDave commented 1 month ago

I've just realised where this error was being reported (I was stupidly checking the HA logs). I believe this is an error/assumption within the HA UI and not this integration and should be logged there appropriately. It looks like something similar was once logged, but nothing came from it.

This integration follows some of the native integrations (e.g. amberelectic) which provide sensors with a unit of measurement in a similar structure (currency/kWh). This is also the unit of measurement the energy dashboard hints the sensor should be in. There is also nowhere in the HA dev docs that state unit_of_measurement should match a set of given values, which suggest there should be no value that's "invalid".

github-actions[bot] commented 5 days ago

This issue has become stale because it has been open for 30 days with no activity. If you still think it's an issue, please respond soon.