Advice needed for personal packages and constructors integration to FHEM

Begonnen von olivierbardot, 12 Februar 2023, 11:53:51

Vorheriges Thema - Nächstes Thema

olivierbardot

Hello everybody

I use FHEM for several years and my 99_myUtils.pm is quite big, mainly written in perl procedural and I begin to rewrite it in perl object.

What is the best way to organise my personal packages and constructors in FHEM data structure ?

is it to store them in 99_myUtils.pm or to create separate packages .pm files? In this case, is there a simple way to make these .pm files compatible to FHEM update/restore ?

Thanks for your kind attention
Best regards
Olivier
Raspis EnOcean TrXCom Linky 1W Telegram Motion EgiGeozone OpenDTU HiveMQ

betateilchen

You can split your code into more than one 99_..Utils.pm files.

The only important thing ist the name of these files: name must start with 99_... and end with ...Utils.pm to be recognized and loaded correctly on FHEM start.

Example from one of my own FHEM installations:


./FHEM/99_calendarUtils.pm
./FHEM/99_colorUtils.pm
./FHEM/99_myUtils.pm
./FHEM/99_notifyUtils.pm
./FHEM/99_rcUtils.pm
./FHEM/99_terrassenUtils.pm
./FHEM/99_timeJobsUtils.pm
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

olivierbardot

Hello
Thanks for your answer

That is what I have already done as it was explained in the docu

But as far as I understand, all my 99_Utils files will be loaded at service restart

I wonder if there is a way to organize that so that only the ones which are called by notifies and subs of my FHEM environment will be loaded (like original FHEM .pm modules are as explained in the docu ; for ex my personal environment use 00_MQTT2_SERVER.pm module so it is loaded but it doesn't use 14_CUL_MAX.pm which remains unloaded).

why ?

it is because, in winter I use personal packages for example related to heating my house and I want the ones for my spa not to be loaded because my spa is out of use in winter so they are not useful for the system in winter.
In summer, I use some for heating my spa and I want the ones for heating my house unloaded.

Is this possible in your opinion ?

Best regards
Olivier

Raspis EnOcean TrXCom Linky 1W Telegram Motion EgiGeozone OpenDTU HiveMQ

betateilchen

One easy way could be:

Store such files as 98_SummerUtils.pm and use FHEM Command "reload 98_SummerUtils.pm" depending on current date (or date range) inside your 99_myUtils.pm

Only files with 99_ will be loaded automatically on FHEM start.

There are a lot of other possibilities and FHEM modules to control such actions based on date/time parameters: at, holiday, Calendar, ...
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

olivierbardot

Hello betateilchen
Very simple and very efficient, thanks a lot !
My ideas were much more complicated  ;)
Kind regards
Olivier
Raspis EnOcean TrXCom Linky 1W Telegram Motion EgiGeozone OpenDTU HiveMQ

Prof. Dr. Peter Henning

I am rather sure that this does not really make sense. A few 100k of memory usage due to unused code do neither slow down FHEM, nor do they pose any danger to the system.

Just think of the many lines of code in all those FHEM modules that are not used for 99% of the time.

On the reverse side you introduce a new point of failure into your system.

LG

pah

olivierbardot

Hello

Many thanks fo your answer

What I have done :
I put my personal packages in xxx.pm files in /opt/fhem/FHEM (beside other original modules).
It seems impossible to create package files whose name files begin with 99_  :)

Then I modified attr WEB editFileList (I know this way of doing is controversial)

My personal packages are automatically loaded on FHEM start.

I agree with Prof. Dr. Peter Henning that it is not a problem that winter packages code is automatically loaded in summer !

Have a nice evening
Cheers
Olivier
Raspis EnOcean TrXCom Linky 1W Telegram Motion EgiGeozone OpenDTU HiveMQ