Skip to content

Commit

Permalink
Feature/23 ground vehicles switch (#26)
Browse files Browse the repository at this point in the history
* #20 - Color of icon based on altitude
* #13 - [wip] Double click to open provider page
* #20 - Updated readme
* #20 - Updated readme
* #13 - Added buttons to external providers
* # 13 - Updated readme
* #13 - Provider logo's
* #23 - Added option to `hide` object to hide ground vehicles
* #23 - Updates readme
* #23 - Fixed filtering issue
  • Loading branch information
fratsloos authored Dec 11, 2023
1 parent 5504a82 commit 0fee27a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/fr24_card.js

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The FR24 card has many configuration options and supports multiple languages.
- [Providers](#providers)
- [Show external providers in popup](#show-external-providers-in-popup)
- [Hide](#hide)
- [General](#general)
- [Hide empty values](#hide-empty-values)
- [F.A.Q.](#faq)
- [Contribute](#contribute)
Expand Down Expand Up @@ -154,7 +155,6 @@ The card supports the following columns. Because there are many different format
| `flight` | Flight number | |
| `icao` | ICAO code of the aircraft | |
| `icon` | Icon for the aircraft | Icon representing altitude and vertical state of the aircraft. See [Icon](#icon). |
| `icon` | Icon for the aircraft | Icon representing altitude and vertical state of the aircraft. See [Icon](#icon). |
| `registration` | Registration code of the aircraft | The registration of the aircraft is calculated based on the reported ICAO code. However, some of the JSON files contain the registration. If the registration is found in the JSON, this data is used. See issue [#15][i15]. |
| `speed` | Reported speed | |
| `squawk` | Squawk code | |
Expand Down Expand Up @@ -240,10 +240,23 @@ hide:

The following keys are available in the object:

| Option | Type | Default | Accepted | Description |
| :------------- | :-------- | :------ | :----------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `old_messages` | `boolean` | `true` | `true`, `false` | By default aircraft data which is received more than 30 seconds ago will be filtered out of the card. Setting this option to `false` will show all aircraft data that is available in the JSON file. |
| `empty` | `array` | | Array with columns, see [examples](#hide-empty-values) | By default, all aircraft are shown, including empty values in the table. With this option it is possible to set the columns that should not be empty. The array acts as an 'or' selector; if one of the columns has an empty value, the plane is not added to the table. This option is especially useful in combination with `sort` and `order`. |
| Option | Type | Default | Accepted | Description |
| :---------------- | :-------- | :------ | :----------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `old_messages` | `boolean` | `true` | `true`, `false` | By default aircraft data which is received more than 30 seconds ago will be filtered out of the card. Setting this option to `false` will show all aircraft data that is available in the JSON file. |
| `ground_vehicles` | `boolean` | `false` | `true`, `false` | By default all reported aircrafts are shown in the card, including ground vehicles. When this option is set to `true` ground vehicles are filtered out of the results. Ground vehicles are defined as results where the reported altitude equals `ground`. |
| `empty` | `array` | | Array with columns, see [examples](#hide-empty-values) | By default, all aircraft are shown, including empty values in the table. With this option it is possible to set the columns that should not be empty. The array acts as an 'or' selector; if one of the columns has an empty value, the plane is not added to the table. This option is especially useful in combination with `sort` and `order`. |

### General

This example shows old messages, but removes ground vehicles:

```yaml
type: custom:fr24-card
entity: sensor.fr24_aircraft
hide:
old_messages: false
ground_vehicles: true
```

### Hide empty values

Expand All @@ -257,7 +270,6 @@ entity: sensor.fr24_aircraft
hide:
empty:
- distance
```

Example to remove all rows where there is no distance *or* track:
Expand All @@ -269,7 +281,6 @@ hide:
empty:
- distance
- track
```

# F.A.Q.
Expand Down
1 change: 1 addition & 0 deletions src/javascript/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Config {
hide: {
old_messages: true,
empty: [],
ground_vehicles: false,
},
inverted_logo: false,
lang: null,
Expand Down
25 changes: 20 additions & 5 deletions src/javascript/fr24_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,36 @@ class FR24Card extends LitElement {
this._distance,
this._lang
);
let addToAircrafts = true;

let add = true;

// Check on old messages
if (this.config.hide.old_messages !== false && aircraft.seen > 30) {
addToAircrafts = false;
} else if (this.config.hide.empty.length > 0) {
add = false;
}

// Check on ground vehicles
if (
this.config.hide.ground_vehicles !== false &&
aircraft.altitude === "ground"
) {
add = false;
}

// Check on empty values for defined columns
if (this.config.hide.empty.length > 0) {
for (let i = 0; i < this.config.hide.empty.length; i++) {
let column = this.config.hide.empty[i];

if (aircraft[column] === null || aircraft[column] === "") {
addToAircrafts = false;
add = false;
break;
}
}
}

if (addToAircrafts) {
// Add aircraft
if (add) {
this._aircrafts.push(aircraft);
}
});
Expand Down

0 comments on commit 0fee27a

Please sign in to comment.