Peer Review von Richards Gewurschtel

Begonnen von RichardCZ, 31 März 2020, 22:17:53

Vorheriges Thema - Nächstes Thema

RichardCZ

Zitat von: KernSani am 18 April 2020, 10:46:19
Ich habe jetzt nicht die ganze Diskussion verfolgt, aber die Maximallänge von Readingnamen konfigurierbar zu machen macht aus meiner Sicht keinen Sinn. Wenn eine Beschränkung existiert möchte ich mich auf die auch verlassen können.

Wer ist "ich" und was bedeutet "sich darauf verlassen"?  ;)

Ich hab's erstmal konfigurierbar im Source. Wenn irgendein Display "sich darauf verlassen will", kann man ja über eine methode zur Selbstauskunft nachdenken.

Readonly my $MAXLEN_DN = 256;  # maximum length of Devicename
Readonly my $MAXLEN_RN = 256;  # maximum length of Readingname


Wenn der user im Code rumfuhrwerkt... gehen wir einfach davon aus, dass er kein Vollhonk ist.

Was macht eigentlich das Display momentan wenn man ihm KriegundFrieden reinstopft? Hat das schonmal wer ausprobiert?

Status Quo:

sub goodDeviceName :Export {
    my $name = shift // return !1;                # according to docs we do not return undef, but false

    return $name =~ m{\A                          # return truth value (true/false) of this rx match
                      [^\s.]                      # for now everything except whitespace and dot is allowed
                      [^\s]{0,$MAXLEN_DN-1}       # continue, but now can also contain '.', up to maximum length
                      \z}xmsi;                    # case insensitive
}

sub goodReadingName :Export {
    my $name = shift // return !1;           # according to docs we do not return undef, but false

    return $name =~ m{\A                     # return truth value (true/false) of this rx match
                      \.?                    # optionally start with a . (internal ReadingName)
                      [^\s]{1,$MAXLEN_RN}    # followed by up to maxlen chars (except whitespace)
                      \z}xmsi;               # case insensitive
}

sub makeDeviceName :Export {
    my $name = shift // return 'UNDEFINED';

    my $len = length $name;                  # get length of given name
    if ($len > $MAXLEN_DN) {                 # if it's longer than the defined maximum
        $name = substr $name, 0, $MAXLEN_DN; # prune it (one could think about a trailing '...')
    }

    $name =~ s/\s/_/gi;                      # replace all whitespaces with _

    return $name;                            # return the transformed name, guaranteed to be compliant
}

sub makeReadingName :Export {
    my $name = shift // return 'UNDEFINED';

    my $len = length $name;                  # get length of given name
    my $max = $name =~ m{\A\.}xms            # if we do start with a dot
            ? $MAXLEN_RN + 1                 # acceptable maxlength is +1
            : $MAXLEN_RN;                    # if we don't it's maxlength

    if ($len > $max)  {                      # we are over allowed length
        $name = substr $name, 0, $max;       # prune it (one could think about a trailing '...')
    }

    $name =~ s/\s/_/gi;                      # replace all whitespaces with _

    return $name;                            # return the transformed name, guaranteed to be compliant
}


Man beachte: Ich verwende Kommentare im Code, das ist auch so neumodisches Zeug.
Das hindert natürlich die Royalität nicht daran zu sagen, der Code sei für ihn nicht wartbar.  ;)

edit:

Tests meinen im Code sind noch Bugs... *seufz*
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

KernSani

Zitat von: RichardCZ am 18 April 2020, 11:02:10
Wer ist "ich" und was bedeutet "sich darauf verlassen"?  ;)


Spontan fällt mir die Tabellendefinition für DBLog ein... Mache ich die Spalte unendlich breit oder kann ich mich auf die 257 verlassen?
Eine Konstante im Source ist für mich übrigens was anderes als ,,konfigurierbar" ;-) Wenn es dazu gedacht ist, die Länge an einer zentralen Stelle ändern zu können falls sich herausstellt 257 reicht nicht, dann gut..


Gesendet von iPhone mit Tapatalk
RasPi: RFXTRX, HM, zigbee2mqtt, mySensors, JeeLink, miLight, squeezbox, Alexa, Siri, ...

rudolfkoenig

ZitatWas macht eigentlich das Display momentan wenn man ihm KriegundFrieden reinstopft?
Das haengt vmtl. vom Browser, und verfuegbaren Hauptspeicher ab.
Diese Argumentationslinie ist vmtl. nicht zielfuehrend, da die Werte ja auch angezeigt werden, und ueber deren Beschraenkung hat bisher keiner nachgedacht.

justme1968

was mir noch zu nicht ascii readings einfällt:

die beschränkung auf ascii ist aus anwender sicht vermutlich schwerwiegender als jede längen beschränkung. userreadings im lokalen zeichensatz sollten möglich sein.

aber: device module sollte nur in aus ausnahmefällen lokalisierte readings verwenden. stattdessen sollte intern alles in so wenig wie möglich standardisierten readings in standardisieren einheiten abgebildet werden.

die übersetzung nach lokal sollte dann in einem zwischenschritt vor der darstellung erfolgen.

nur so lassen sich module einfach übersetzer, fhem selber in unterschiedlichen sprachen verwenden und selbst geschrieben routinen sprachunabhängif halten.

im prinzip gibt es hier schon anfänge mit reading kategorien und mit dem units modul.
hue, tradfri, alexa-fhem, homebridge-fhem, LightScene, readingsGroup, ...

https://github.com/sponsors/justme-1968

RichardCZ

Zitat von: rudolfkoenig am 18 April 2020, 11:23:01
Das haengt vmtl. vom Browser, und verfuegbaren Hauptspeicher ab.
Diese Argumentationslinie ist vmtl. nicht zielfuehrend, da die Werte ja auch angezeigt werden, und ueber deren Beschraenkung hat bisher keiner nachgedacht.

Ja, danke für die explizite Erwähnung des DoS Potentials. Ansonsten halte ich die komplementäre Argumentationslinie für nicht zielführend

a) natürlich habe ich darüber nachgedacht, nur kotze ich mich tatsächlich nicht über alles worüber ich nachdenke hier aus. (*)
b) Es kann ja nicht sein mit "bislang haben wir gar keine Restriktion, also macht es keinen Sinn mit einer anzufangen" zu argumentieren


(*) Das mag für jemanden jetzt überraschend sein.

PS: Außerdem bin ich traurig, HoBo liegt auf der Intensivstation

Invalid characters in name (not A-Za-z0-9._): WEB
Please define WEB 5e70a1c5-f33f-8c0a-8a10-dc51d292283b1446 first
...
Invalid characters in name (not A-Za-z0-9._): Logfile
Please define Logfile 5e70a1c5-f33f-8c0a-f36c-445cb4cf1efdf61a first
Invalid characters in name (not A-Za-z0-9._): autocreate
Please define autocreate 5e70a1c5-f33f-8c0a-bd1c-819f511b7ed9970e first
...
Invalid characters in name (not A-Za-z0-9._): eventTypes
Please define eventTypes 5e70a1c5-f33f-8c0a-9808-9a22a285b3e97831 first
Invalid characters in name (not A-Za-z0-9._): mySwitch1
Please define mySwitch1 5e70bb38-f33f-8c0a-d642-9eea3373709f4bb0 first
...
Invalid characters in name (not A-Za-z0-9._): myLamp1
Please define myLamp1 5e70bd92-f33f-8c0a-4be1-5db61ba18525e13a first
...
Invalid characters in name (not A-Za-z0-9._): soldisk
Please define soldisk 5e71e4ea-f33f-f89d-5aef-b9b8cc4ecb3aa27f first
Invalid characters in name (not A-Za-z0-9._): Qnap1
Please define Qnap1 5e724130-f33f-f89d-3edc-2180dd34b5c98481 first
Invalid characters in name (not A-Za-z0-9._): MyTTS
Please define MyTTS 5e8340b5-f33f-f89d-2c4c-69958c6e95faa032 first

... ad Inf.

Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

rudolfkoenig

Zitatb) Es kann ja nicht sein mit "bislang haben wir gar keine Restriktion, also macht es keinen Sinn mit einer anzufangen" zu argumentieren
Ich bin ja auf der Seite der Laengenbegrenzer :) ich will nur die "Gegner" mit schluessigen Argumentationen ueberzeugen.

Wg. der Intensivstation: setuuid hat die Trennung der Argumente vergeigt.

RichardCZ

Resistance is futile. You will be assimilated!
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

RichardCZ

Und wennschondennschon. Das behalte ich jetzt zum Testen.
Die Sortierreihenfolge ist komisch - isn't it?
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

RichardCZ

#83
Jaa liebe Leute. Sieht gut aus. Aber warum sieht das gut aus? Weil ich Tests habe und ihr nicht. ätschbätsch.

Jetzt mal benevolent konstruktiv: FHEM Stolperstein in goodReadingName (jetzt schon)

return ($name =~ m/^[a-z0-9._\-\/]+$/i || $name =~ m/^\./);

FHEM ist zwar "Real-Life getestet"(tm), aber erlaubt hier hidden Readingnames die z.B. Leerzeichen enthalten -> *Boom*
Das fängt zwar in den meisten Fällen der split ab, aber k.A. ob nicht doch irgendwo ein Readingname auf einem Seitenkanal antanzen kann.




edit: Devicenamen tun auch, siehe Anhang

Würde mich über Testvorschläge freuen. Soweit ich rumgestochert habe ist mir noch nichts um die Ohren geflogen.
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

rudolfkoenig

ZitatFHEM ist zwar "Real-Life getestet"(tm), aber erlaubt hier hidden Readingnames die z.B. Leerzeichen enthalten -> *Boom*
Mir ist kein Weg bekannt, wie ein Benutzer ein *Boom* erzeugen kann.
Da ich aber nicht alle Module, die diese Funktion aufrufen, nach Unsinn absuchen will, habe ich die Pruefung (und die Korrektur in makeReadingName) erweitert: \s wird in .name nicht zugelassen.

RichardCZ

Quick&Dirty Skript
https://gl.petatech.eu/root/HomeBot/-/blob/d117007c527108a1a271926fcf7456221f3f909b/scripts/pod2wiki.pl
nimmt künftig PODs wie z.B.
https://gl.petatech.eu/root/HomeBot/-/blob/d117007c527108a1a271926fcf7456221f3f909b/lib/HoBo.pm
und macht daraus
https://gl.petatech.eu/root/HomeBot/-/wikis/API-Test




künftig ist angedacht, dass https://gl.petatech.eu/root/HomeBot/-/wikis/DevelopmentModuleAPI
automatisch erzeugt wird.

Hätte ich heute nicht soviel Zeit mit gewissen Dingen verplempert, wäre das schon viel weiter. Lessons learned.
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

RichardCZ

$ fhem2hobo.pl
Only in HOBO:
27_SNMP_Template.pm
remote: Enumerating objects: 74, done.
remote: Counting objects: 100% (74/74), done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 74 (delta 35), reused 59 (delta 21), pack-reused 0
Unpacking objects: 100% (74/74), 21.23 KiB | 289.00 KiB/s, done.
From https://github.com/fhem/mod-Buienradar
   fe84261..d9c0c17  development/3.0.6 -> origin/development/3.0.6
* [new branch]      development/3.0.7 -> origin/development/3.0.7
59_Buienradar.pm...
*** Diff detected! *** (42695 chars)
-> copying to Hobo sandbox.
88_WEBCOUNT.pm...
*** Diff detected! *** (4530 chars)
-> copying to Hobo sandbox.
60_uba.pm...
*** Diff detected! *** (30784 chars)
-> copying to Hobo sandbox.
98_unittest.pm...
*** Diff detected! *** (19229 chars)
-> copying to Hobo sandbox.
Enumerating objects: 18, done.
Counting objects: 100% (18/18), done.
Delta compression using up to 8 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (16/16), 28.50 KiB | 4.07 MiB/s, done.
Total 16 (delta 8), reused 0 (delta 0), pack-reused 0
To https://gl.petatech.eu/root/HomeBot.git
   4672798..7f1c2a0  master -> master


fhem2hobo.pl ist nun zu einem Aggregator aufgebohrt worden. Sprich: mittlerweile holt es sich nicht nur Sachen aus dem offiziellen/Haupt- FHEM SVN, sondern auch aus anderen Quellen.
Derzeit habe ich ein paar Github repos (mod-Buienradar  mod-webcount  uba  UnitTest) zum Test.
Siehe https://gl.petatech.eu/root/HomeBot/-/commit/df9cf516cc87a252c49b01a3db3e794cf2051b40 ff
Selbstverständlich erfolgt der Merger bzw. die diff-Betrachtungen bereits mit normalisiertem Code.
Jetzt könnte ich doch eigentlich auch Byte09's Repo einfügen. Wo isses?

Ein Ring, sie zu knechten, sie alle zu finden,
Ins Dunkel zu treiben und ewig zu binden

;)
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

RichardCZ

https://gl.petatech.eu/root/HomeBot/-/jobs/164

das 98_FhemTestUtils test-Framework funktioniert nun auch unter HoBo und wurde ins GitLab CI integriert (s.o.)

Und Rudolf bekommt von mir das goldene Schwimmabzeichen für Freistil in der Klärgrube.
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

RichardCZ

Zitat von: RichardCZ am 05 Juni 2020, 08:42:52
...GitLab CI Pipeline (siehe z.B.  https://gl.petatech.eu/root/HomeBot/pipelines/118), die seit gestern bei mir auch erfolgreich statische Binaries baut (aber noch nicht abholt - artifact download und dann irgendwo auf dem Web als "release" bereitstellt - kommt noch).

Das ist hiermit geschehen, siehe https://gl.petatech.eu/root/HomeBot/pipelines

* guggst Du rechts, ist da ein download Symbol (jeweils oberste/neueste Pipeline)
* wenn man draufklickt kommt ein "download build_static artifacts"
* wenn man da drauf klickt, wird ein artifacts.zip (ca. 8MB) geladen.
* entpackt ist das ein 29MB HoBo_x86_64 (sorry, tut noch nicht auf dem RasPi) (*)

Das enthält:

* ein Perl 5.30.2
* alle benötigten Module (also Systemmodule, CPAN module für FHEM/HoBo)
* alle Module aus FHEM und lib

Device::USB und Mojolicious macht noch Ärger, alles andere sollte da sein.

Theoretisch sollte also das hier gehen:

$ ./HoBo_x86_64
Usage:
as server: hobo.pl [-d] {<configfile>|configDB}
as client: hobo.pl [host:]port cmd cmd cmd...
testing:   hobo.pl -t <testfile>.t


Und falls ihr das Teil ins FHEM Installationsverzeichnis schiebt und mit

./HoBo_x86_64 fhem.cfg

aufruft (fhem.pl vorher beenden), dann sollte unter localhost:8083 irgendwas röcheln. Vielleicht.
Der Witz ist, das sollte auch auf einem Linux System passieren wo gar kein Perl installiert ist.




(*) Immer noch ein halbes Königreich für ein HowTo für eine RasPi VM unter Proxmox
Witty House Infrastructure Processor (WHIP) is a modern and
comprehensive full-stack smart home framework for the 21st century.

Wzut

#89
Start als root schlägt fehl , start als normaler User ging nachdem dieser User Schreibrechte auf die aktuelle fhem.log hatte.
Beim ersten edit der config und save :
undefined subroutine &HoBo::Command::WriteStatefile called at HoBo/Command.pm line 1072.
Compilation failed in require.


2020.06.05 19:31:38 1: reload: Error:Modul 10_MAX deactivated:
Can't locate Date/Parse.pm in @INC (you may need to install the Date::Parse module) (@INC contains: ./lib ./FHEM lib . CODE(0x563401bdd1b8) ./FHEM/lib) at ./FHEM/10_MAX.pm line 32.
BEGIN failed--compilation aborted at ./FHEM/10_MAX.pm line 32.


update Versuch :
2020.06.05 20:03:53 1: Downloading https://fhem.de/fhemupdate/controls_fhem.txt
2020.06.05 20:03:53 1: ERROR evaluating {Log('1','Downloading https://fhem.de/fhemupdate/controls_fhem.txt')}: Undefined subroutine &HoBo::Log::FW_logInform called at HoBo/Log.pm line 65.

Undefined subroutine &HoBo::Log::FW_logInform called at HoBo/Log.pm line 65.
Compilation failed in require
.


Maintainer der Module: MAX, MPD, UbiquitiMP, UbiquitiOut, SIP, BEOK, readingsWatcher