thomluther / ha-anker-solix

Home Assistant integration for Anker Solix Power devices
MIT License
296 stars 4 forks source link

Issues with currency symbol, Invalid currency code : € #35

Closed FWeinb closed 7 months ago

FWeinb commented 7 months ago

System Health details

System Information

version core-2024.4.1
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.1.0-18-amd64
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1401 Downloaded Repositories | 18
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 9 -- | -- resources | 12 views | 23 mode | storage
Recorder oldest_recorder_run | April 3, 2024 at 20:08 -- | -- current_recorder_run | April 5, 2024 at 22:26 estimated_db_size | 129.24 MiB database_engine | sqlite database_version | 3.44.2

Checklist

Describe the issue

When configuring the price currency this component offers €,$,£,¥,₹,원 and will configure the entity to use that unit. That unit will be used as-is in the Intl.NumberFormat as the currency code causing the following issue:

format_number.ts:73 RangeError: Invalid currency code : €
    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)

This API is expecting a well-formed 3-letter ISO 4217 currency codes I would expect this component to convert between these symbols and the ISO 4217 currency code.

Reproduction steps

  1. Go to a Power Site Type 2 device
  2. Open the browsers development tools
  3. Observe the Stacktrace in the console

Debug logs

Not applicable as this is only a frontend issue

Diagnostics dump

No response

thomluther commented 7 months ago

Hi, Can you desribe in more detail how you see this issue? The App officially only supports € and $, not a currency code. Its simply a char that must be sent. I tried also with other single currency chars as supported by the integration and did not see an issue with it. Even the App displayed them (like £,¥), but of course a change in the App only allows $ or € And I never saw an error in the frontend/browser for the currency unit selection or change, because it is simply a character, But maybe newer HA core changed something that broke it?

FWeinb commented 7 months ago

When I view the cost savings entity on the a dashboard (example was the Power Site Type 2 device page) this error is thrown:

image

This happens because the "€" symbol inside the currency property for the Intl.NumberFormat is used. I think to communicate the unit towards HA this component needs to translate "€" into "EUR" and vice-versa towards the Anker API.

thomluther commented 7 months ago

Hm, sounds weird, because the number and the unit are completely different things in HA. However, the entity is classified as currency as I remember, and maybe therefore HA expect this to be iso format currency unit. If that is the case, I'm going to change the classification of the entity to accept any chars as unit.

FWeinb commented 7 months ago

Thanks for all you work on this component! Glad you could identify a solution to this.

thomluther commented 7 months ago

I cannot recreate this issue with Firefox, so it seems to be browser related on how monetary values are managed. For compatability, I'm going to remove the SensorDeviceClass.MONETARY declaration from this sensor so that it does not have a device class. That should allow any char as unit to be handled correctly.