mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
This commit is contained in:
parent
c67a182cf2
commit
b4b6286172
89 changed files with 672 additions and 666 deletions
|
|
@ -35,7 +35,7 @@ class Device extends Model
|
|||
'pause_until' => 'datetime',
|
||||
];
|
||||
|
||||
public function getBatteryPercentAttribute()
|
||||
public function getBatteryPercentAttribute(): int|float
|
||||
{
|
||||
$volts = $this->last_battery_voltage;
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ class Device extends Model
|
|||
return round($voltage, 2);
|
||||
}
|
||||
|
||||
public function getWifiStrengthAttribute()
|
||||
public function getWifiStrengthAttribute(): int
|
||||
{
|
||||
$rssi = $this->last_rssi_level;
|
||||
if ($rssi >= 0) {
|
||||
|
|
@ -106,11 +106,7 @@ class Device extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
if ($this->proxy_cloud_response && $this->proxy_cloud_response['update_firmware']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->proxy_cloud_response && $this->proxy_cloud_response['update_firmware'];
|
||||
}
|
||||
|
||||
public function getFirmwareUrlAttribute(): ?string
|
||||
|
|
@ -231,7 +227,7 @@ class Device extends Model
|
|||
return false;
|
||||
}
|
||||
|
||||
$now = $now ? Carbon::instance($now) : now();
|
||||
$now = $now instanceof DateTimeInterface ? Carbon::instance($now) : now();
|
||||
|
||||
// Handle overnight ranges (e.g. 22:00 to 06:00)
|
||||
return $this->sleep_mode_from < $this->sleep_mode_to
|
||||
|
|
@ -245,7 +241,7 @@ class Device extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
$now = $now ? Carbon::instance($now) : now();
|
||||
$now = $now instanceof DateTimeInterface ? Carbon::instance($now) : now();
|
||||
$from = $this->sleep_mode_from;
|
||||
$to = $this->sleep_mode_to;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,10 +38,8 @@ class Playlist extends Model
|
|||
}
|
||||
|
||||
// Check weekday
|
||||
if ($this->weekdays !== null) {
|
||||
if (! in_array(now()->dayOfWeek, $this->weekdays)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->weekdays !== null && ! in_array(now()->dayOfWeek, $this->weekdays)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->active_from !== null && $this->active_until !== null) {
|
||||
|
|
@ -53,10 +51,8 @@ class Playlist extends Model
|
|||
if ($now >= $this->active_from || $now <= $this->active_until) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if ($now >= $this->active_from && $now <= $this->active_until) {
|
||||
return true;
|
||||
}
|
||||
} elseif ($now >= $this->active_from && $now <= $this->active_until) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -153,9 +153,7 @@ class PlaylistItem extends Model
|
|||
$plugins = Plugin::whereIn('id', $pluginIds)->get();
|
||||
|
||||
// Sort the collection to match plugin_ids order
|
||||
$plugins = $plugins->sortBy(function ($plugin) use ($pluginIds) {
|
||||
return array_search($plugin->id, $pluginIds);
|
||||
})->values();
|
||||
$plugins = $plugins->sortBy(fn ($plugin): int|string|false => array_search($plugin->id, $pluginIds))->values();
|
||||
|
||||
foreach ($plugins as $index => $plugin) {
|
||||
$size = $this->getLayoutSize($index);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Plugin extends Model
|
|||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
static::creating(function ($model): void {
|
||||
if (empty($model->uuid)) {
|
||||
$model->uuid = Str::uuid();
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ class Plugin extends Model
|
|||
$currentValue = $this->configuration[$fieldKey] ?? null;
|
||||
|
||||
// If the field has a default value and no current value is set, it's not missing
|
||||
if (($currentValue === null || $currentValue === '' || (is_array($currentValue) && empty($currentValue))) && ! isset($field['default'])) {
|
||||
if (($currentValue === null || $currentValue === '' || ($currentValue === [])) && ! isset($field['default'])) {
|
||||
return true; // Found a required field that is not set and has no default
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ class Plugin extends Model
|
|||
// Split URLs by newline and filter out empty lines
|
||||
$urls = array_filter(
|
||||
array_map('trim', explode("\n", $this->polling_url)),
|
||||
fn ($url) => ! empty($url)
|
||||
fn ($url): bool => ! empty($url)
|
||||
);
|
||||
|
||||
// If only one URL, use the original logic without nesting
|
||||
|
|
@ -237,7 +237,7 @@ class Plugin extends Model
|
|||
// Converts to: {% assign temp_filtered = collection | filter: "key", "value" %}{% for item in temp_filtered %}
|
||||
$template = preg_replace_callback(
|
||||
'/{%\s*for\s+(\w+)\s+in\s+([^|%}]+)\s*\|\s*([^%}]+)%}/',
|
||||
function ($matches) {
|
||||
function ($matches): string {
|
||||
$variableName = mb_trim($matches[1]);
|
||||
$collection = mb_trim($matches[2]);
|
||||
$filter = mb_trim($matches[3]);
|
||||
|
|
@ -245,7 +245,7 @@ class Plugin extends Model
|
|||
|
||||
return "{% assign {$tempVarName} = {$collection} | {$filter} %}{% for {$variableName} in {$tempVarName} %}";
|
||||
},
|
||||
$template
|
||||
(string) $template
|
||||
);
|
||||
|
||||
return $template;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue