fhem / fhem/LuftdatenInfo

use data driven solutions instad of elsif

Open
#44 0 comments 0 reactions 1 assignee Claimed by @Igami View on GitHub
enhancement FHEM Forum
Dominant language
Perl
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

> ```
> if($_->{value_type} =~ m{P0$}x){
> $_->{value_type} = "PM1";
> }
> elsif($_->{value_type} =~ m{P1$}x){
> $_->{value_type} = "PM10";
> }
> elsif($_->{value_type} =~ m{P2$}x){
> $_->{value_type} = "PM2.5";
> }
> elsif($_->{value_type} =~ m{_air_quality$}x){
> $_->{value_type} = "airQuality";
> }
> ```
>
>
> => Data-driven Lösung (ggf. mit Modifiern)
>
>
> ```
> my %hash = (
> qr{P0$} => 'PM1',
> qr{P1$} => 'PM10',
> qr{_air_quality$} => 'airQuality',
> ...
> );
>
> for my $rx (keys %hash) {
> if ($name->{value_type} =~ $rx) {
> $name->{value_type} = $hash{$rx};
> last;
> }
> }
> ```
>
>
> Das "lohnt" sich schon ab 3-4 solcher elsif Bandwurmglieder.

https://forum.fhem.de/index.php/topic,110348.msg1044070.html#msg1044070

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.