17 Commits

Author SHA1 Message Date
Jeremias Wolff
231014566a Merge pull request #8 from notnullxyz/main
Fix wind index. Add debug logging. Get it working with the http dep
2023-11-01 07:54:46 +01:00
notnullxyz
9ffdea3702 PHP Linting (Pint) 2023-11-01 06:51:40 +00:00
Marlon van der Linde
4cb82af4c1 Merge pull request #1 from comes/main
Merge catchup. Confusing day.
2023-11-01 08:51:14 +02:00
Jeremias Wolff
7145396ca5 Merge pull request #10 from comes/comes-patch-2
Update pint.yml
2023-10-30 19:24:23 +01:00
comes
a4e7450cfd PHP Linting (Pint) 2023-10-30 18:23:28 +00:00
Jeremias Wolff
6f66e00145 Update pint.yml 2023-10-30 19:23:07 +01:00
Jeremias Wolff
8a15050614 Merge pull request #9 from comes/comes-patch-1
Create pint.yml
2023-10-30 19:18:16 +01:00
Jeremias Wolff
1002ab7847 Create pint.yml 2023-10-30 19:17:58 +01:00
Marlon van der Linde
829a802ce1 Fix wind index. Add debug logging. Get it working with the http dep 2023-10-30 16:48:29 +02:00
Jeremias Wolff
79814c7f23 Merge pull request #6 from Djblaik/main
Fixed missing  outdoorTempGust, solarradiation and uvi data
2023-05-29 09:32:42 +02:00
Jeremias Wolff
2899d38167 Update EcowittExportCommand.php
ci
2023-05-29 09:32:08 +02:00
David Blaik
9f3685349d Update EcowittExportCommand.php
//replace uvi empty values with 0
2023-05-29 14:20:31 +10:00
David Blaik
0fe6abf221 Update EcowittExportCommand.php
updated list values for outdoorTempGust, solarradiation and uvi to resolve missing data in the csv
2023-05-29 14:16:50 +10:00
Jeremias Wolff
d9ec3ffbee Merge pull request #5 from comes/upgrade-10 2023-04-18 20:45:10 +02:00
Jeremias Wolff
cb0b334476 revert file 2023-04-18 20:44:12 +02:00
Jeremias Wolff
81ae516367 Merge pull request #4 from comes/3-error-on-running-export-command 2023-04-18 20:40:55 +02:00
Jeremias Wolff
8c266b5841 upgrade to 10.x 2023-04-18 20:40:09 +02:00
12 changed files with 3567 additions and 633 deletions

View File

@@ -12,5 +12,4 @@ trim_trailing_whitespace = true
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.yml] [*.yml]
indent_style = space
indent_size = 2 indent_size = 2

23
.github/workflows/pint.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: PHP Linting (Pint)
on:
workflow_dispatch:
push:
branches-ignore:
- 'dependabot/npm_and_yarn/*'
jobs:
phplint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: "laravel-pint"
uses: aglipanci/laravel-pint-action@2.3.0
with:
preset: laravel
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: PHP Linting (Pint)
skip_fetch: true

View File

@@ -15,6 +15,7 @@ class EcowittExportCommand extends Command
protected $endDate; protected $endDate;
protected $ecowitt_account; protected $ecowitt_account;
protected $ecowitt_passphrase; protected $ecowitt_passphrase;
/** /**
@@ -55,6 +56,7 @@ class EcowittExportCommand extends Command
if (empty($this->ecowitt_account) || empty($this->ecowitt_passphrase)) { if (empty($this->ecowitt_account) || empty($this->ecowitt_passphrase)) {
$this->error('Ecowitt Username or passphrase required!'); $this->error('Ecowitt Username or passphrase required!');
return 1; return 1;
} }
@@ -66,7 +68,6 @@ class EcowittExportCommand extends Command
$this->endDate = Carbon::parse($this->argument('endDate'))->endOfDay(); $this->endDate = Carbon::parse($this->argument('endDate'))->endOfDay();
$device_ids->each(function ($deviceId) use ($session_id) { $device_ids->each(function ($deviceId) use ($session_id) {
$startDate = $this->startDate->clone(); $startDate = $this->startDate->clone();
$endDate = $this->endDate->clone(); $endDate = $this->endDate->clone();
// declare output variable // declare output variable
@@ -91,98 +92,118 @@ class EcowittExportCommand extends Command
$ecowitt = $response->json(); $ecowitt = $response->json();
$this->times = data_get($ecowitt,'times',[]); $this->times = data_get($ecowitt, 'times', []);
// Temperature in C // Temperature in C
$this->debug('fetch outdoor temp'); $this->debug('fetch outTemp');
$outdoorTemp = $this->getData($ecowitt, 'list.tempf.list.tempf'); $outdoorTemp = $this->getData($ecowitt, 'list.tempf.list.tempf');
// Feels Like in C // Feels Like in C
$this->debug('fetch outdoor temp gust'); $this->debug('fetch outTempApp');
$outdoorTempGust = $this->getData($ecowitt, 'list.tempf.list.sendible_temp'); $outdoorTempApp = $this->getData($ecowitt, 'list.tempf.list.apparent_temp');
// Dew Point in C // Dew Point in C
$this->debug('collecting: Dew Point in C'); $this->debug('fetch dewpoint');
$outdoorDewTemp = $this->getData($ecowitt, 'list.tempf.list.drew_temp'); $outdoorTempDew = $this->getData($ecowitt, 'list.tempf.list.drew_temp'); // yes ecowitt calls it drew_temp :)
// humidity in % // humidity in %
$this->debug('collecting: humidity in %'); $this->debug('fetch outHumidity %');
$outdoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity'); $outdoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity');
// temp indoor in C // temp indoor in C
$this->debug('collecting: temp indoor in C'); $this->debug('fetch inTemp');
$indoorTemp = $this->getData($ecowitt, 'list.tempinf.list.tempinf'); $indoorTemp = $this->getData($ecowitt, 'list.tempinf.list.tempinf');
// humidityin in % // humidityin in %
$this->debug('collecting: humidityin in %'); $this->debug('fetch inHumidityin %');
$indoorHumidity = $this->getData($ecowitt, 'list.humidity.list.humidity'); $indoorHumidity = $this->getData($ecowitt, 'list.humidityin.list.humidityin');
// solar in lx -- Solar and UVI // solar in lx -- Solar and UVI
$this->debug('collecting: solar in lx -- Solar and UVI'); $this->debug('fetch solar radiation');
$solarradiation = $this->getData($ecowitt, 'list.solarradiation.list.solarradiation'); $solarRadiation = $this->getData($ecowitt, 'list.so_uv.list.solarradiation');
// uv // uv
$this->debug('collecting: uv'); $this->debug('fetch uv index');
$uvi = $this->getData($ecowitt, 'list.uv.list.uv'); $uvi = $this->getData($ecowitt, 'list.so_uv.list.uv');
//replace empty values with 0
foreach ($uvi as $key => $value) {
if (empty($value)) {
$uvi[$key] = '0';
}
}
// rainrate in mm/hr b // rainrate in mm/hr b
$this->debug('collecting: rainrate in mm/hr b'); $this->debug('fetch rainratein');
$rainRateH = $this->getData($ecowitt, 'list.rain.list.rainratein'); $rainRateIn = $this->getData($ecowitt, 'list.rain.list.rainratein');
// daily rainrate total mm/hr // daily rainrate total mm/hr
$this->debug('collecting: daily rainrate total mm/hr'); $this->debug('fetch dailyrainin');
$rainRateDaily = $this->getData($ecowitt, 'list.rain.list.dailyrainin'); $dailyRainIn = $this->getData($ecowitt, 'list.rain.list.dailyrainin');
// wind_speed in m/s // wind_speed in m/s
$this->debug('collecting: wind_speed in m/s'); $this->debug('fetch windspeedmph (kmh)');
$windspeed = $this->getData($ecowitt, 'list.wind_speed.list.windspeedmph'); $windSpeed = $this->getData($ecowitt, 'list.wind.list.windspeedmph'); // this key is called mph but units in data struct is kmh :/
// windGust // windGust
$this->debug('collecting: windGust'); $this->debug('fetch windgustmph (kmh)');
$windGust = $this->getData($ecowitt, 'list.wind_speed.list.windgustmph'); $windGust = $this->getData($ecowitt, 'list.wind.list.windgustmph'); // wind gust key called mph but units in data struct is kmh
// winddir in degree // winddir in degree
$this->debug('collecting: winddir in degree'); $this->debug('fetch winddir');
$windir = $this->getData($ecowitt, 'list.winddir.list.winddir'); $windDir = $this->getData($ecowitt, 'list.wind.list.winddir');
// pressure relative in hPa // pressure relative in hPa
$this->debug('collecting: pressure relative in hPa'); $this->debug('fetch baromrelin');
$pressureRel = $this->getData($ecowitt, 'list.pressure.list.baromrelin'); $pressureRel = $this->getData($ecowitt, 'list.pressure.list.baromrelin');
// pressure absolute in hPa // pressure absolute in hPa
$this->debug('collecting: pressure absolute in hPa'); $this->debug('fetch baromabsin');
$pressureAbs = $this->getData($ecowitt, 'list.pressure.list.baromabsin'); $pressureAbs = $this->getData($ecowitt, 'list.pressure.list.baromabsin');
foreach ($outdoorTemp as $date => $temp) { foreach ($outdoorTemp as $date => $temp) {
if (! $temp) {
$this->debug('Skipping a bogus index');
continue;
}
$this->debug('unpacking $temp: '.$temp);
$tmp = [ $tmp = [
'date_and_time' => $date, // %Y-%m-%d %H:%M:%S 'time' => $date, // %Y-%m-%d %H:%M:%S
'temp_out' => $temp, // degree
'temp_out_gust' => data_get($outdoorTempGust, $date), // degree 'outTemp' => $temp, // degree
'temp_out_dew' => data_get($outdoorDewTemp, $date), // degree 'outTempApp' => data_get($outdoorTempApp, $date), // degree
'humid_out' => data_get($outdoorHumidity, $date), // percent 'dewpoint' => data_get($outdoorTempDew, $date), // degree
'temp_in' => data_get($indoorTemp, $date), // degree 'outHumidity' => data_get($outdoorHumidity, $date), // percent
'humid_in' => data_get($indoorHumidity, $date), // percent
'rad' => data_get($solarradiation, $date), // lx 'inTemp' => data_get($indoorTemp, $date), // degree
'inHumidity' => data_get($indoorHumidity, $date), // percent
'radiation' => data_get($solarRadiation, $date), // lx
'uv' => data_get($uvi, $date), 'uv' => data_get($uvi, $date),
'rain' => data_get($rainRateH, // mm
'rain_rate' => data_get($rainRateIn, // mm
$date $date
), ),
'rain_daily' => data_get($rainRateDaily, $date), // mm 'rain_daily' => data_get($dailyRainIn, $date), // mm
'wind' => data_get($windspeed, // m_per_second
'wind_speed' => data_get($windSpeed, // m_per_second
$date $date
), ),
'wind_gust' => data_get($windGust, $date), // m_per_second 'windGust' => data_get($windGust, $date), // m_per_second
'wind_dir' => data_get($windir, $date), // degree_compass 'windDir' => data_get($windDir, $date), // degree_compass
'pressure_rel' => data_get($pressureRel, $date), // hPa
'pressure_abs' => data_get($pressureAbs, $date), // hPa 'pressure_abs' => data_get($pressureAbs, $date), // hPa
'pressure_rel' => data_get($pressureRel, $date),
]; ];
$outputData[] = $tmp; $outputData[] = $tmp;
} }
$startDate = $startDate->addDay()->startOfDay(); $startDate = $startDate->addDay()->startOfDay();
} while ( $startDate->lte($endDate) ); } while ($startDate->lte($endDate));
$this->export(getcwd() . "/ecowitt_{$deviceId}.csv", $outputData);
$outFile = getcwd()."/export_ecowitt_{$deviceId}.csv";
$this->export($outFile, $outputData);
$this->debug('exported to output file: '.$outFile);
}); });
} }
@@ -191,6 +212,7 @@ class EcowittExportCommand extends Command
return collect(data_get($stack, $key)) return collect(data_get($stack, $key))
->mapWithKeys(function ($value, $idx) { ->mapWithKeys(function ($value, $idx) {
$dateTime = data_get($this->times, $idx); $dateTime = data_get($this->times, $idx);
return [$dateTime => $value ?: null]; return [$dateTime => $value ?: null];
}); });
} }
@@ -217,8 +239,6 @@ class EcowittExportCommand extends Command
/** /**
* fetch all available device IDs * fetch all available device IDs
* @param $session_id
* @return \Illuminate\Support\Collection
*/ */
protected function getDeviceIds($session_id): \Illuminate\Support\Collection protected function getDeviceIds($session_id): \Illuminate\Support\Collection
{ {
@@ -229,7 +249,7 @@ class EcowittExportCommand extends Command
->asForm() ->asForm()
->post('https://webapi.www.ecowitt.net/index/get_devices', [ ->post('https://webapi.www.ecowitt.net/index/get_devices', [
'uid' => '', 'uid' => '',
'type' => 1 'type' => 1,
]); ]);
$devices = collect(data_get($deviceResponse->json(), 'device_list')); $devices = collect(data_get($deviceResponse->json(), 'device_list'));
@@ -241,34 +261,29 @@ class EcowittExportCommand extends Command
/** /**
* Takes in a filename and an array associative data array and outputs a csv file * Takes in a filename and an array associative data array and outputs a csv file
* @param string $fileName
* @param array $data
*/ */
protected function export(string $fileName, array $data) { protected function export(string $fileName, array $data)
if(isset($data['0'])){ {
if (isset($data['0'])) {
$fp = fopen($fileName, 'w+'); $fp = fopen($fileName, 'w+');
fputs($fp, implode(',',array_keys($data['0'])) . "\n"); fwrite($fp, implode(',', array_keys($data['0']))."\n");
foreach($data AS $values){ foreach ($data as $values) {
fputs($fp, implode(',', $values) . "\n"); fwrite($fp, implode(',', $values)."\n");
} }
fclose($fp); fclose($fp);
} }
} }
/** /**
* @param string $msg * @param mixed ...$args
* @param mixed ...$args
*/ */
protected function debug(string $msg, ...$args) protected function debug(string $msg, ...$args)
{ {
if ($this->option('debug')) { if ($this->option('debug')) {
$this->info($msg); $this->info($msg);
if (!empty($args)) { if (! empty($args)) {
dump($args); dump($args);
} }
} }
} }
} }

View File

@@ -8,20 +8,16 @@ class AppServiceProvider extends ServiceProvider
{ {
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void
*/ */
public function boot() public function boot(): void
{ {
// //
} }
/** /**
* Register any application services. * Register any application services.
*
* @return void
*/ */
public function register() public function register(): void
{ {
// //
} }

View File

@@ -5,6 +5,10 @@
"homepage": "https://github.com/comes/ecowitt2weewx", "homepage": "https://github.com/comes/ecowitt2weewx",
"type": "project", "type": "project",
"license": "MIT", "license": "MIT",
"support": {
"issues": "https://github.com/comes/ecowitt2weewx/issues",
"source": "https://github.com/comes/ecowitt2weewx"
},
"authors": [ "authors": [
{ {
"name": "Jeremias Wolff", "name": "Jeremias Wolff",
@@ -12,15 +16,22 @@
} }
], ],
"require": { "require": {
"php": "^8.0", "php": "^8.1",
"guzzlehttp/guzzle": "^7.5", "guzzlehttp/guzzle": "^7.5",
"illuminate/http": "^9.47", "illuminate/http": "^10.0",
"laravel-zero/framework": "^9.2", "laravel-zero/framework": "^10.0.2",
"nesbot/carbon": "^2.65" "nunomaduro/termwind": "^1.15.1"
},
"require-dev": {
"laravel/pint": "^1.8",
"mockery/mockery": "^1.5.1",
"pestphp/pest": "^2.5"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
} }
}, },
"autoload-dev": { "autoload-dev": {
@@ -36,7 +47,7 @@
"pestphp/pest-plugin": true "pestphp/pest-plugin": true
} }
}, },
"minimum-stability": "dev", "minimum-stability": "stable",
"prefer-stable": true, "prefer-stable": true,
"bin": ["ecowitt2weewx"] "bin": ["ecowitt2weewx"]
} }

3926
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,19 @@ return [
'env' => 'development', 'env' => 'development',
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Autoloaded Service Providers | Autoloaded Service Providers

View File

@@ -56,10 +56,13 @@ return [
'hidden' => [ 'hidden' => [
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class, NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
Symfony\Component\Console\Command\DumpCompletionCommand::class,
Symfony\Component\Console\Command\HelpCommand::class, Symfony\Component\Console\Command\HelpCommand::class,
Illuminate\Console\Scheduling\ScheduleRunCommand::class, Illuminate\Console\Scheduling\ScheduleRunCommand::class,
Illuminate\Console\Scheduling\ScheduleListCommand::class,
Illuminate\Console\Scheduling\ScheduleFinishCommand::class, Illuminate\Console\Scheduling\ScheduleFinishCommand::class,
Illuminate\Foundation\Console\VendorPublishCommand::class, Illuminate\Foundation\Console\VendorPublishCommand::class,
LaravelZero\Framework\Commands\StubPublishCommand::class,
], ],
/* /*

View File

@@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false" <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupStaticAttributes="false" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php" bootstrap="vendor/autoload.php"
colors="true" colors="true"
convertErrorsToExceptions="true" >
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites> <testsuites>
<testsuite name="Feature"> <testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory> <directory suffix="Test.php">./tests/Feature</directory>
@@ -16,9 +12,9 @@
<directory suffix="Test.php">./tests/Unit</directory> <directory suffix="Test.php">./tests/Unit</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<coverage processUncoveredFiles="true"> <source>
<include> <include>
<directory suffix=".php">./app</directory> <directory suffix=".php">./app</directory>
</include> </include>
</coverage> </source>
</phpunit> </phpunit>

View File

@@ -3,15 +3,14 @@
namespace Tests; namespace Tests;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
trait CreatesApplication trait CreatesApplication
{ {
/** /**
* Creates the application. * Creates the application.
*
* @return \Illuminate\Foundation\Application
*/ */
public function createApplication() public function createApplication(): Application
{ {
$app = require __DIR__.'/../bootstrap/app.php'; $app = require __DIR__.'/../bootstrap/app.php';

View File

@@ -1,7 +0,0 @@
<?php
test('inspiring command', function () {
$this->artisan('inspiring')
->expectsOutput('Simplicity is the ultimate sophistication.')
->assertExitCode(0);
});

View File

@@ -1,3 +1,45 @@
<?php <?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/
uses(Tests\TestCase::class)->in('Feature'); uses(Tests\TestCase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something(): void
{
// ..
}