Skip to content

Commit

Permalink
Run linter
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed Oct 14, 2023
1 parent 33cab9e commit 9d0a391
Show file tree
Hide file tree
Showing 24 changed files with 1,833 additions and 1,124 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'no-console': 'error',
'prettier/prettier': [
'error',
Expand Down
88 changes: 49 additions & 39 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,86 @@ import { Utils } from './utils';

export class MeteoalarmEventInfo {
constructor(
public type: MeteoalarmEventType,
public fullName: string,
public icon: string
public type: MeteoalarmEventType,
public fullName: string,
public icon: string,
) {}

get translationKey(): string {
return 'events.' + this.fullName.toLocaleLowerCase()
.replace(' ', '_')
.replace('/', '_')
.replace('-', '_');
return (
'events.' +
this.fullName.toLocaleLowerCase().replace(' ', '_').replace('/', '_').replace('-', '_')
);
}
}

export class MeteoalarmLevelInfo {
constructor(
public type: MeteoalarmLevelType,
public fullName: string,
public color: string
public type: MeteoalarmLevelType,
public fullName: string,
public color: string,
) {}

get translationKey(): string {
return 'messages.' + this.fullName.toLocaleLowerCase()
.replace(' ', '_')
.replace('/', '_')
.replace('-', '_');
return (
'messages.' +
this.fullName.toLocaleLowerCase().replace(' ', '_').replace('/', '_').replace('-', '_')
);
}
}

export class MeteoalarmData {
static get events(): MeteoalarmEventInfo[] {
// Use some new icons
if(!Utils.minHAversion(2022, 8)) {
if (!Utils.minHAversion(2022, 8)) {
/* eslint-disable-next-line no-console */
console.warn('MeteoalarmCard: You are using old HA version! Please update to at least 2022.08 for the best experience.');
console.warn(
'MeteoalarmCard: You are using old HA version! Please update to at least 2022.08 for the best experience.',
);
}
const tsunami = Utils.minHAversion(2022, 6) ? 'tsunami' : 'waves';
const dust = Utils.minHAversion(2022, 8) ? 'weather-dust' : 'weather-windy';

// This list should be ordered from most to least dangerous
return [
new MeteoalarmEventInfo(MeteoalarmEventType.Nuclear, 'Nuclear Event', 'radioactive'),
new MeteoalarmEventInfo(MeteoalarmEventType.Hurricane, 'Hurricane', 'weather-hurricane'),
new MeteoalarmEventInfo(MeteoalarmEventType.Tornado, 'Tornado', 'weather-tornado'),
new MeteoalarmEventInfo(MeteoalarmEventType.CoastalEvent, 'Coastal Event', tsunami),
new MeteoalarmEventInfo(MeteoalarmEventType.Tsunami, 'Tsunami', tsunami),
new MeteoalarmEventInfo(MeteoalarmEventType.ForestFire, 'Forest Fire', 'pine-tree-fire'),
new MeteoalarmEventInfo(MeteoalarmEventType.Avalanches, 'Avalanches', 'image-filter-hdr'),
new MeteoalarmEventInfo(MeteoalarmEventType.Earthquake, 'Earthquake', 'image-broken-variant'),
new MeteoalarmEventInfo(MeteoalarmEventType.Volcano, 'Volcanic Activity','volcano-outline'),
new MeteoalarmEventInfo(MeteoalarmEventType.Flooding, 'Flooding', 'home-flood'),
new MeteoalarmEventInfo(MeteoalarmEventType.SeaEvent, 'Sea Event', 'ferry'),
new MeteoalarmEventInfo(MeteoalarmEventType.Thunderstorms, 'Thunderstorms', 'weather-lightning'),
new MeteoalarmEventInfo(MeteoalarmEventType.Rain, 'Rain', 'weather-pouring'),
new MeteoalarmEventInfo(MeteoalarmEventType.SnowIce, 'Snow/Ice', 'weather-snowy-heavy'),
new MeteoalarmEventInfo(MeteoalarmEventType.HighTemperature, 'High Temperature', 'thermometer'),
new MeteoalarmEventInfo(MeteoalarmEventType.LowTemperature, 'Low Temperature', 'snowflake'),
new MeteoalarmEventInfo(MeteoalarmEventType.Dust, 'Dust', dust),
new MeteoalarmEventInfo(MeteoalarmEventType.Wind, 'Wind', 'weather-windy'),
new MeteoalarmEventInfo(MeteoalarmEventType.Fog, 'Fog', 'weather-fog'),
new MeteoalarmEventInfo(MeteoalarmEventType.AirQuality, 'Air Quality', 'air-filter'),
new MeteoalarmEventInfo(MeteoalarmEventType.Unknown, 'Unknown Event', 'alert-circle-outline')
new MeteoalarmEventInfo(MeteoalarmEventType.Nuclear, 'Nuclear Event', 'radioactive'),
new MeteoalarmEventInfo(MeteoalarmEventType.Hurricane, 'Hurricane', 'weather-hurricane'),
new MeteoalarmEventInfo(MeteoalarmEventType.Tornado, 'Tornado', 'weather-tornado'),
new MeteoalarmEventInfo(MeteoalarmEventType.CoastalEvent, 'Coastal Event', tsunami),
new MeteoalarmEventInfo(MeteoalarmEventType.Tsunami, 'Tsunami', tsunami),
new MeteoalarmEventInfo(MeteoalarmEventType.ForestFire, 'Forest Fire', 'pine-tree-fire'),
new MeteoalarmEventInfo(MeteoalarmEventType.Avalanches, 'Avalanches', 'image-filter-hdr'),
new MeteoalarmEventInfo(MeteoalarmEventType.Earthquake, 'Earthquake', 'image-broken-variant'),
new MeteoalarmEventInfo(MeteoalarmEventType.Volcano, 'Volcanic Activity', 'volcano-outline'),
new MeteoalarmEventInfo(MeteoalarmEventType.Flooding, 'Flooding', 'home-flood'),
new MeteoalarmEventInfo(MeteoalarmEventType.SeaEvent, 'Sea Event', 'ferry'),
new MeteoalarmEventInfo(
MeteoalarmEventType.Thunderstorms,
'Thunderstorms',
'weather-lightning',
),
new MeteoalarmEventInfo(MeteoalarmEventType.Rain, 'Rain', 'weather-pouring'),
new MeteoalarmEventInfo(MeteoalarmEventType.SnowIce, 'Snow/Ice', 'weather-snowy-heavy'),
new MeteoalarmEventInfo(
MeteoalarmEventType.HighTemperature,
'High Temperature',
'thermometer',
),
new MeteoalarmEventInfo(MeteoalarmEventType.LowTemperature, 'Low Temperature', 'snowflake'),
new MeteoalarmEventInfo(MeteoalarmEventType.Dust, 'Dust', dust),
new MeteoalarmEventInfo(MeteoalarmEventType.Wind, 'Wind', 'weather-windy'),
new MeteoalarmEventInfo(MeteoalarmEventType.Fog, 'Fog', 'weather-fog'),
new MeteoalarmEventInfo(MeteoalarmEventType.AirQuality, 'Air Quality', 'air-filter'),
new MeteoalarmEventInfo(MeteoalarmEventType.Unknown, 'Unknown Event', 'alert-circle-outline'),
];
}

static get levels(): MeteoalarmLevelInfo[] {
return [
new MeteoalarmLevelInfo(MeteoalarmLevelType.Red, 'Red', '#db4437'),
new MeteoalarmLevelInfo(MeteoalarmLevelType.Red, 'Red', '#db4437'),
new MeteoalarmLevelInfo(MeteoalarmLevelType.Orange, 'Orange', '#EE5A24'),
new MeteoalarmLevelInfo(MeteoalarmLevelType.Yellow, 'Yellow', '#ff9800'),
new MeteoalarmLevelInfo(MeteoalarmLevelType.None, 'None', 'inherit')
new MeteoalarmLevelInfo(MeteoalarmLevelType.None, 'None', 'inherit'),
];
}

Expand Down
57 changes: 35 additions & 22 deletions src/editor-warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ import { MeteoalarmIntegration, MeteoalarmIntegrationEntityType } from './types'

export function generateEditorWarnings(
integration: MeteoalarmIntegration | undefined,
entities: EntityConfig[] | undefined
entities: EntityConfig[] | undefined,
): TemplateResult {
// If entities are undefined, default to empty array
if(!Array.isArray(entities)) entities = [];
if(!integration) return html``;
if (!Array.isArray(entities)) entities = [];
if (!integration) return html``;

return html`
${duplicateWarning(entities)}
${missingExpectedEntityWarning(integration, entities)}
${duplicateWarning(entities)} ${missingExpectedEntityWarning(integration, entities)}
${tooManyEntitiesWarning(integration, entities)}
`;
`;
}

/**
* Generate warning for CurrentExpected integrations when second entity is not provided
*/
function missingExpectedEntityWarning(integration: MeteoalarmIntegration, entities: EntityConfig[]): TemplateResult {
function missingExpectedEntityWarning(
integration: MeteoalarmIntegration,
entities: EntityConfig[],
): TemplateResult {
const validEntity = integration?.metadata.type == MeteoalarmIntegrationEntityType.CurrentExpected;
if(validEntity && entities.length == 1) {
if (validEntity && entities.length == 1) {
return html`
<ha-alert alert-type="warning" title=${localize('common.warning')}>
<ha-alert
alert-type="warning"
title=${localize('common.warning')}
>
${localize('editor.error.expected_entity')}
</ha-alert>
`;
Expand All @@ -37,32 +42,40 @@ function missingExpectedEntityWarning(integration: MeteoalarmIntegration, entiti
* Generate warning when user provides two identical entities in editor
*/
function duplicateWarning(entities: EntityConfig[]): TemplateResult {
const uniqueEntities = Array.from(new Set(entities.map(x => x.entity)));
const hasDuplicateEntities = uniqueEntities.length != entities.length;
if(hasDuplicateEntities) {
const uniqueEntities = Array.from(new Set(entities.map((x) => x.entity)));
const hasDuplicateEntities = uniqueEntities.length != entities.length;
if (hasDuplicateEntities) {
return html`
<ha-alert alert-type="warning" title=${localize('common.warning')}>
<ha-alert
alert-type="warning"
title=${localize('common.warning')}
>
${localize('editor.error.duplicate')}
</ha-alert>
`;
`;
}
return html``;
}

/**
* Generate warning when there are too much entities provided
*/
function tooManyEntitiesWarning(integration: MeteoalarmIntegration, entities: EntityConfig[]): TemplateResult {
function tooManyEntitiesWarning(
integration: MeteoalarmIntegration,
entities: EntityConfig[],
): TemplateResult {
const shouldConsider = integration.metadata.entitiesCount > 0;
if(shouldConsider && entities.length > integration.metadata.entitiesCount) {
if (shouldConsider && entities.length > integration.metadata.entitiesCount) {
return html`
<ha-alert alert-type="warning" title=${localize('common.warning')}>
${localize('editor.error.too_many_entities')
.replace('{expected}', String(integration.metadata.entitiesCount))
.replace('{got}', String(entities.length))}
<ha-alert
alert-type="warning"
title=${localize('common.warning')}
>
${localize('editor.error.too_many_entities')
.replace('{expected}', String(integration.metadata.entitiesCount))
.replace('{got}', String(entities.length))}
</ha-alert>
`;
`;
}
return html``;
}

Loading

0 comments on commit 9d0a391

Please sign in to comment.