MrBartusek / MeteoalarmCard

Meteoalarm, Météo-France and DWD severe weather warnings card for Home Assistant Lovelace UI ⛈️
MIT License
135 stars 48 forks source link

env_canada not working when configured in French #100

Closed mdallaire closed 1 year ago

mdallaire commented 2 years ago

Describe the bug

I am trying to configure the card with Environment Canada but I get the following error:

Error: Selected integration doesn't match selected entities: sensor.envcan_statements, sensor.envcan_warnings, sensor.envcan_watches.

Those sensors exist and have the valid information from the integration.

Steps to reproduce

No response

Screenshots

image image image image

Card version

v2.0.0

Integration type

Environnement Canada

Installation type

Home Assistant Community Store (HACS)

Card Configuration

name: Meteoalarm
type: custom:meteoalarm-card
integration: env_canada
entities:
  - entity: sensor.envcan_statements
  - entity: sensor.envcan_warnings
  - entity: sensor.envcan_watches

Integration Configuration

No yaml configuration, configured in the integrations

image

MrBartusek commented 2 years ago

Hey, thanks for the repport! Can you open developer tools and send entity attributes in yaml form?

mdallaire commented 2 years ago

Here is the attributes for the warning.

location: XYZ
station: Aéroport int. de Montréal-Mirabel
alert_1: Avertissement De Chaleur
alert_time_1: 19 juillet 2022 15h40 HAE
attribution: Données fournies par Environnement Canada
icon: mdi:alert-octagon
friendly_name: envcan Warnings

I poked at the code a bit and I think the issue is that the attribution is in French in my configuration. When you configure the integration you can chose between French and English and obtain the information in the chosen language from Environment Canada.

https://github.com/MrBartusek/MeteoalarmCard/blob/5a5bac1194cbed7b759f4fb80ce48ffbee17a42c/src/integrations/env_canada.ts#L38

mdallaire commented 2 years ago

Looking at it even more it looks like the whole thing would need to be translated. If you want I could do a PR with a new integration env_canada_fr.ts which would be the exact same as the original but with the French strings. I am no python expert so there may be a more elegant way of doing this too. Just let me know and I can take care of the translation if you need help.

MrBartusek commented 2 years ago

@mdallaire Yeah I thought this was the case. You shouldn't really make a different integration just edit this if statement you've linked. Let me know If you want to work on this!

mdallaire commented 2 years ago

I translated the eventTypes section by simply adding the french strings for the various types. However I have no idea on how to add the 'Données fournies par Environnement Canada' to the existing logic.

        // From: https://www.canada.ca/fr/environnement-changement-climatique/services/types-previsions-meteorologiques-utilisation/publiques/criteres-alertes-meteo.html   
            'Poussée d’air arctique': MeteoalarmEventType.SnowIce,
        // Same as English  'Blizzard': MeteoalarmEventType.SnowIce,
            'Poudrerie': MeteoalarmEventType.SnowIce,
            'Tempête de poussière': MeteoalarmEventType.Dust,
            'Froid extrême': MeteoalarmEventType.LowTemperature,
            'Refroidissement soudain': MeteoalarmEventType.SnowIce,
            'Brouillard': MeteoalarmEventType.Fog,
            'Bruine verglaçante': MeteoalarmEventType.SnowIce,
            'Pluie verglaçante': MeteoalarmEventType.SnowIce,
            'Gel': MeteoalarmEventType.SnowIce,
            'Chaleur': MeteoalarmEventType.HighTemperature,
            'Ouragan': MeteoalarmEventType.Hurricane,
            'Pluie': MeteoalarmEventType.Rain,
            'Orage violent': MeteoalarmEventType.Thunderstorms,
            'Neige': MeteoalarmEventType.SnowIce,
            'Bourrasques de neige': MeteoalarmEventType.SnowIce,
            'Onde de tempête': MeteoalarmEventType.Thunderstorms,
            'Tornade': MeteoalarmEventType.Tornado,
            'Tempête tropicale': MeteoalarmEventType.Hurricane,
        // Same as English  'Tsunami': MeteoalarmEventType.Tsunami,
            'Météorologique': MeteoalarmEventType.Unknown,
            'Vents': MeteoalarmEventType.Wind,
            'Tempête hivernale': MeteoalarmEventType.SnowIce
MrBartusek commented 2 years ago

Something like that

public supports(entity: EnvCanadaEntity): boolean {
        const isStateNumber = !Number.isNaN(Number(entity.state));
        const validAttribution = entity.attributes.attribution == 'Data provided by Environment Canada' || entity.attributes.attribution == 'Données fournies par Environnement Canada'
        return validAttribution && isStateNumber && this.getEntityType(entity) !== undefined);
    }