Aggiunta collegamento a APIRest di HomeAssistant (e qualche test)

This commit is contained in:
Amministratore 2023-10-10 12:28:53 +02:00
parent cbbaf0bf3e
commit bf8bf40a1d
5 changed files with 638 additions and 2 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\HomeAssistantAPI;
class HomeAssistantAPIController extends Controller
{
// Connessione RestAPI di HomeAssistant
public function getContatore()
{
$kwh = HomeAssistantAPI::getSensorState('sensor.contatore_casa');
return $kwh->state;
}
public function getStatoPompa()
{
$statoPompa = HomeAssistantAPI::getSensorState('switch.pompa_pozzo');
return $statoPompa->state;
//dd($statoPompa);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;
class HomeAssistantAPI extends Model
{
use HasFactory;
public static function getSensorState($sensor)
{
$result=Http::withHeaders(
[
'Authorization'=>'Bearer '.env('HA_TOKEN'),
'Content-Type'=>'application/json',
]
)->get('https://ha.lavorain.cloud/api/states/'.$sensor);
return json_decode($result);
}
}

View File

@ -26,6 +26,7 @@
"sfneal/view-export": "^2.10",
"snapappointments/bootstrap-select": "^1.13",
"spatie/laravel-backup": "^7.0",
"spatie/laravel-google-calendar": "^3.6",
"spatie/laravel-permission": "^5.10",
"webklex/laravel-imap": "^2.4"
},

588
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7f685f85c8c510c071ddd43bbd2682a0",
"content-hash": "b97b1d1172c798a3b3b8a87527b31518",
"packages": [
{
"name": "almasaeed2010/adminlte",
@ -1173,6 +1173,69 @@
},
"time": "2022-09-18T07:06:19+00:00"
},
{
"name": "firebase/php-jwt",
"version": "v6.9.0",
"source": {
"type": "git",
"url": "https://github.com/firebase/php-jwt.git",
"reference": "f03270e63eaccf3019ef0f32849c497385774e11"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/f03270e63eaccf3019ef0f32849c497385774e11",
"reference": "f03270e63eaccf3019ef0f32849c497385774e11",
"shasum": ""
},
"require": {
"php": "^7.4||^8.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.5||^7.4",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"psr/cache": "^1.0||^2.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0"
},
"suggest": {
"ext-sodium": "Support EdDSA (Ed25519) signatures",
"paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
},
"type": "library",
"autoload": {
"psr-4": {
"Firebase\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Neuman Vong",
"email": "neuman+pear@twilio.com",
"role": "Developer"
},
{
"name": "Anant Narayanan",
"email": "anant@php.net",
"role": "Developer"
}
],
"description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
"homepage": "https://github.com/firebase/php-jwt",
"keywords": [
"jwt",
"php"
],
"support": {
"issues": "https://github.com/firebase/php-jwt/issues",
"source": "https://github.com/firebase/php-jwt/tree/v6.9.0"
},
"time": "2023-10-05T00:24:42+00:00"
},
{
"name": "fruitcake/laravel-cors",
"version": "v2.2.0",
@ -1253,6 +1316,177 @@
"abandoned": true,
"time": "2022-02-23T14:25:13+00:00"
},
{
"name": "google/apiclient",
"version": "v2.15.1",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-api-php-client.git",
"reference": "7a95ed29e4b6c6859d2d22300c5455a92e2622ad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/7a95ed29e4b6c6859d2d22300c5455a92e2622ad",
"reference": "7a95ed29e4b6c6859d2d22300c5455a92e2622ad",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~6.0",
"google/apiclient-services": "~0.200",
"google/auth": "^1.28",
"guzzlehttp/guzzle": "~6.5||~7.0",
"guzzlehttp/psr7": "^1.8.4||^2.2.1",
"monolog/monolog": "^2.9||^3.0",
"php": "^7.4|^8.0",
"phpseclib/phpseclib": "^3.0.19"
},
"require-dev": {
"cache/filesystem-adapter": "^1.1",
"composer/composer": "^1.10.22",
"phpcompatibility/php-compatibility": "^9.2",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0",
"symfony/css-selector": "~2.1",
"symfony/dom-crawler": "~2.1"
},
"suggest": {
"cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.x-dev"
}
},
"autoload": {
"files": [
"src/aliases.php"
],
"psr-4": {
"Google\\": "src/"
},
"classmap": [
"src/aliases.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
],
"support": {
"issues": "https://github.com/googleapis/google-api-php-client/issues",
"source": "https://github.com/googleapis/google-api-php-client/tree/v2.15.1"
},
"time": "2023-09-13T21:46:39+00:00"
},
{
"name": "google/apiclient-services",
"version": "v0.318.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-api-php-client-services.git",
"reference": "908a866797b9731352e650997112c8c3a0347ac5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/908a866797b9731352e650997112c8c3a0347ac5",
"reference": "908a866797b9731352e650997112c8c3a0347ac5",
"shasum": ""
},
"require": {
"php": "^7.4||^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7||^8.5.13"
},
"type": "library",
"autoload": {
"files": [
"autoload.php"
],
"psr-4": {
"Google\\Service\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
],
"support": {
"issues": "https://github.com/googleapis/google-api-php-client-services/issues",
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.318.0"
},
"time": "2023-10-02T01:10:14+00:00"
},
{
"name": "google/auth",
"version": "v1.31.0",
"source": {
"type": "git",
"url": "https://github.com/googleapis/google-auth-library-php.git",
"reference": "22209fddd0c06f3f8e3cb4aade0b352aa00f9888"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/22209fddd0c06f3f8e3cb4aade0b352aa00f9888",
"reference": "22209fddd0c06f3f8e3cb4aade0b352aa00f9888",
"shasum": ""
},
"require": {
"firebase/php-jwt": "^6.0",
"guzzlehttp/guzzle": "^6.2.1|^7.0",
"guzzlehttp/psr7": "^2.4.5",
"php": "^7.4||^8.0",
"psr/cache": "^1.0||^2.0||^3.0",
"psr/http-message": "^1.1||^2.0"
},
"require-dev": {
"guzzlehttp/promises": "^2.0",
"kelvinmo/simplejwt": "0.7.1",
"phpseclib/phpseclib": "^3.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.0.0",
"sebastian/comparator": ">=1.2.3",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"phpseclib/phpseclib": "May be used in place of OpenSSL for signing strings or for token management. Please require version ^2."
},
"type": "library",
"autoload": {
"psr-4": {
"Google\\Auth\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Google Auth Library for PHP",
"homepage": "http://github.com/google/google-auth-library-php",
"keywords": [
"Authentication",
"google",
"oauth2"
],
"support": {
"docs": "https://googleapis.github.io/google-auth-library-php/main/",
"issues": "https://github.com/googleapis/google-auth-library-php/issues",
"source": "https://github.com/googleapis/google-auth-library-php/tree/v1.31.0"
},
"time": "2023-10-05T20:39:00+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.1.1",
@ -3519,6 +3753,123 @@
},
"time": "2022-01-27T09:35:39+00:00"
},
{
"name": "paragonie/constant_time_encoding",
"version": "v2.6.3",
"source": {
"type": "git",
"url": "https://github.com/paragonie/constant_time_encoding.git",
"reference": "58c3f47f650c94ec05a151692652a868995d2938"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938",
"reference": "58c3f47f650c94ec05a151692652a868995d2938",
"shasum": ""
},
"require": {
"php": "^7|^8"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"vimeo/psalm": "^1|^2|^3|^4"
},
"type": "library",
"autoload": {
"psr-4": {
"ParagonIE\\ConstantTime\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com",
"role": "Maintainer"
},
{
"name": "Steve 'Sc00bz' Thomas",
"email": "steve@tobtu.com",
"homepage": "https://www.tobtu.com",
"role": "Original Developer"
}
],
"description": "Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)",
"keywords": [
"base16",
"base32",
"base32_decode",
"base32_encode",
"base64",
"base64_decode",
"base64_encode",
"bin2hex",
"encoding",
"hex",
"hex2bin",
"rfc4648"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/constant_time_encoding/issues",
"source": "https://github.com/paragonie/constant_time_encoding"
},
"time": "2022-06-14T06:56:20+00:00"
},
{
"name": "paragonie/random_compat",
"version": "v9.99.100",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a",
"reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a",
"shasum": ""
},
"require": {
"php": ">= 7"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*",
"vimeo/psalm": "^1"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"polyfill",
"pseudorandom",
"random"
],
"support": {
"email": "info@paragonie.com",
"issues": "https://github.com/paragonie/random_compat/issues",
"source": "https://github.com/paragonie/random_compat"
},
"time": "2020-10-15T08:29:30+00:00"
},
{
"name": "phenx/php-font-lib",
"version": "0.5.4",
@ -3789,6 +4140,165 @@
],
"time": "2023-02-25T19:38:58+00:00"
},
{
"name": "phpseclib/phpseclib",
"version": "3.0.23",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "866cc78fbd82462ffd880e3f65692afe928bed50"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/866cc78fbd82462ffd880e3f65692afe928bed50",
"reference": "866cc78fbd82462ffd880e3f65692afe928bed50",
"shasum": ""
},
"require": {
"paragonie/constant_time_encoding": "^1|^2",
"paragonie/random_compat": "^1.4|^2.0|^9.99.99",
"php": ">=5.6.1"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"suggest": {
"ext-dom": "Install the DOM extension to load XML formatted public keys.",
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"type": "library",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib3\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
],
"support": {
"issues": "https://github.com/phpseclib/phpseclib/issues",
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.23"
},
"funding": [
{
"url": "https://github.com/terrafrost",
"type": "github"
},
{
"url": "https://www.patreon.com/phpseclib",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib",
"type": "tidelift"
}
],
"time": "2023-09-18T17:22:01+00:00"
},
{
"name": "psr/cache",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/3.0.0"
},
"time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/clock",
"version": "1.0.0",
@ -5485,6 +5995,80 @@
],
"time": "2022-03-08T10:32:05+00:00"
},
{
"name": "spatie/laravel-google-calendar",
"version": "3.6.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-google-calendar.git",
"reference": "2c292b0eaa743105643987cd73c1c187d6183784"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/laravel-google-calendar/zipball/2c292b0eaa743105643987cd73c1c187d6183784",
"reference": "2c292b0eaa743105643987cd73c1c187d6183784",
"shasum": ""
},
"require": {
"google/apiclient": "^2.2",
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
"nesbot/carbon": "^2.63",
"php": "^7.2|^8.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3|^1.4",
"orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0",
"phpunit/phpunit": "^8.4|^9.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\GoogleCalendar\\GoogleCalendarServiceProvider"
],
"aliases": {
"GoogleCalendar": "Spatie\\GoogleCalendar\\GoogleCalendarFacade"
}
}
},
"autoload": {
"psr-4": {
"Spatie\\GoogleCalendar\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Manage events on a Google Calendar",
"homepage": "https://github.com/spatie/laravel-google-calendar",
"keywords": [
"calendar",
"event",
"google",
"laravel-google-calendar",
"schedule",
"spatie"
],
"support": {
"source": "https://github.com/spatie/laravel-google-calendar/tree/3.6.0"
},
"funding": [
{
"url": "https://spatie.be/open-source/support-us",
"type": "custom"
}
],
"time": "2023-04-20T06:44:04+00:00"
},
{
"name": "spatie/laravel-package-tools",
"version": "1.12.1",
@ -10861,5 +11445,5 @@
"php": "^7.3|^8.0"
},
"platform-dev": [],
"plugin-api-version": "2.6.0"
"plugin-api-version": "2.2.0"
}

View File

@ -27,3 +27,4 @@ Route::get('/calendar', [TagController::class,'calendartest'])->name('calendar')
// Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/test', function(){ return view('test');});
Route::get('/test/ha-energy',[App\Http\Controllers\HomeAssistantAPIController::class,'getStatoPompa']);