44include_once __DIR__ . '/timetest.php ' ;
55include_once __DIR__ . '/getcontentstest.php ' ;
66
7- class PowerPrice extends IPSModule
7+ class PowerPrice extends IPSModuleStrict
88{
99 use TestTime;
1010 use TestGetContents;
1111
12- public function Create ()
12+ public function Create () : void
1313 {
1414 $ this ->RegisterPropertyString ('Provider ' , 'aWATTar ' );
1515 $ this ->RegisterPropertyString ('EPEXSpotToken ' , '' );
@@ -27,7 +27,10 @@ public function Create()
2727 IPS_SetVariableProfileText ('Cent ' , '' , ' ct ' );
2828 }
2929
30- $ this ->RegisterVariableString ('MarketData ' , $ this ->Translate ('Market Data ' ), '~TextBox ' , 0 );
30+ $ created = $ this ->RegisterVariableString ('MarketData ' , $ this ->Translate ('Market Data ' ), '~TextBox ' , 0 );
31+ if ($ created ) {
32+ $ this ->SetValue ('MarketData ' , '[] ' );
33+ }
3134 $ this ->RegisterVariableFloat ('CurrentPrice ' , $ this ->Translate ('Current Price ' ), 'Cent ' , 1 );
3235
3336 $ this ->SetVisualizationType (1 );
@@ -39,13 +42,13 @@ public function Create()
3942 $ this ->RegisterTimer ('UpdateCurrentPrice ' , 35000 , 'SPX_UpdateCurrentPrice($_IPS["TARGET"]); ' );
4043 }
4144
42- public function ApplyChanges ()
45+ public function ApplyChanges () : void
4346 {
4447 parent ::ApplyChanges ();
4548 $ this ->Update ();
4649 }
4750
48- public function GetConfigurationForm ()
51+ public function GetConfigurationForm () : string
4952 {
5053 // No helper here, we want to use the file in both testing and production
5154 $ form = json_decode (file_get_contents (__DIR__ . '/form.json ' ), true );
@@ -67,14 +70,14 @@ public function GetConfigurationForm()
6770 return json_encode ($ form );
6871 }
6972
70- public function Update ()
73+ public function Update () : void
7174 {
7275 // Keep for backward compatibility, but use separate methods
7376 $ this ->UpdateMarketData ();
7477 $ this ->UpdateCurrentPrice ();
7578 }
7679
77- public function UpdateMarketData ()
80+ public function UpdateMarketData () : void
7881 {
7982 $ marketData = '[] ' ;
8083 switch ($ this ->ReadPropertyString ('Provider ' )) {
@@ -119,7 +122,7 @@ public function UpdateMarketData()
119122 $ this ->UpdateCurrentPrice ();
120123 }
121124
122- public function UpdateCurrentPrice ()
125+ public function UpdateCurrentPrice () : void
123126 {
124127 $ marketData = $ this ->GetValue ('MarketData ' );
125128 $ currentTime = $ this ->getTime ();
@@ -148,7 +151,7 @@ public function UpdateCurrentPrice()
148151 $ this ->SetTimerInterval ('UpdateCurrentPrice ' , max (($ nextUpdate - $ this ->getTime ()) * 1000 , 1 ));
149152 }
150153
151- public function GetVisualizationTile ()
154+ public function GetVisualizationTile () : string
152155 {
153156 // Add static HTML content from file to make editing easier
154157 // No helper here, we want to use the file in both testing and production
@@ -167,7 +170,7 @@ public function GetVisualizationTile()
167170 return $ module ;
168171 }
169172
170- public function UIChangeProvider (string $ Provider )
173+ public function UIChangeProvider (string $ Provider ) : void
171174 {
172175 $ this ->UpdateFormField ('aWATTarMarket ' , 'visible ' , $ Provider === 'aWATTar ' );
173176 $ this ->UpdateFormField ('TibberPostalCode ' , 'visible ' , $ Provider === 'Tibber ' );
@@ -186,7 +189,7 @@ public function UIChangeProvider(string $Provider)
186189 $ this ->UpdateFormField ('PriceTax ' , 'visible ' , $ Provider != 'Tibber ' );
187190 }
188191
189- private function NormalizeAndReduce ($ data )
192+ private function NormalizeAndReduce ($ data ) : string
190193 {
191194 $ this ->SendDebug ('NormalizeAndReduce - Input Data ' , json_encode ($ data ), 0 );
192195 $ result = [];
@@ -242,7 +245,7 @@ private function NormalizeAndReduce($data)
242245 return json_encode ($ result );
243246 }
244247
245- private function FetchFromEntsoe ($ market )
248+ private function FetchFromEntsoe ($ market ) : string
246249 {
247250 switch ($ market ) {
248251 case 'AT ' :
@@ -310,7 +313,7 @@ private function FetchFromEntsoe($market)
310313 break ;
311314 default :
312315 $ this ->SendDebug ('FetchFromEntsoe - Unsupported Market ' , $ market , 0 );
313- return [] ;
316+ return json_encode ([]) ;
314317 }
315318 $ start = mktime (0 , 0 , 0 , intval (date ('m ' , $ this ->getTime ())), intval (date ('d ' , $ this ->getTime ())), intval (date ('Y ' , $ this ->getTime ())));
316319 $ end = strtotime ('+2 days ' , $ start );
@@ -433,7 +436,7 @@ private function FetchFromEntsoe($market)
433436 return $ this ->NormalizeAndReduce ($ result );
434437 }
435438
436- private function FetchFromAwattar ($ market )
439+ private function FetchFromAwattar ($ market ) : string
437440 {
438441 $ start = mktime (0 , 0 , 0 , intval (date ('m ' , $ this ->getTime ())), intval (date ('d ' , $ this ->getTime ())), intval (date ('Y ' , $ this ->getTime ())));
439442 $ end = strtotime ('+2 days ' , $ start );
@@ -465,7 +468,7 @@ private function FetchFromAwattar($market)
465468 return $ this ->NormalizeAndReduce ($ decodedData ['data ' ]);
466469 }
467470
468- private function FetchFromTibber ($ postalCode )
471+ private function FetchFromTibber ($ postalCode ) : string
469472 {
470473 $ this ->SendDebug ('FetchFromTibber - Postal Code ' , $ postalCode , 0 );
471474 $ response = $ this ->getContents (sprintf ('https://tibber.com/de/api/lookup/price-overview?postalCode=%s ' , $ postalCode ));
@@ -511,7 +514,7 @@ private function FetchFromTibber($postalCode)
511514 return json_encode ($ result );
512515 }
513516
514- private function GetPriceResolution ($ data = null , $ startField = 'start ' , $ endField = 'end ' , $ divisorToSeconds = 1 )
517+ private function GetPriceResolution ($ data = null , $ startField = 'start ' , $ endField = 'end ' , $ divisorToSeconds = 1 ) : int
515518 {
516519 if ($ data === null ) {
517520 $ data = json_decode ($ this ->GetValue ('MarketData ' ), true );
0 commit comments