<?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);
    }

}

