Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.7 KiB
PHP
Raw Permalink Normal View History

2018-05-09 08:05:17 -05:00
<?php
namespace App\Models;
2020-11-03 17:18:31 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2021-04-14 07:33:41 -05:00
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
2020-11-03 17:18:31 +01:00
2019-01-22 17:04:28 -06:00
class Sensor extends DeviceRelatedModel
2018-05-09 08:05:17 -05:00
{
2020-11-03 17:18:31 +01:00
use HasFactory;
2018-05-09 08:05:17 -05:00
public $timestamps = false;
protected $primaryKey = 'sensor_id';
protected static $icons = [
'airflow' => 'angle-double-right',
'ber' => 'sort-amount-desc',
'charge' => 'battery-half',
2019-01-20 13:37:08 -06:00
'chromatic_dispersion' => 'indent',
'cooling' => 'thermometer-full',
'count' => 'hashtag',
'current' => 'bolt fa-flip-horizontal',
'dbm' => 'sun-o',
'delay' => 'clock-o',
'eer' => 'snowflake-o',
'fanspeed' => 'refresh',
'frequency' => 'line-chart',
'humidity' => 'tint',
'load' => 'percent',
'loss' => 'percentage',
'power' => 'power-off',
'power_consumed' => 'plug',
'power_factor' => 'calculator',
'pressure' => 'thermometer-empty',
'quality_factor' => 'arrows',
'runtime' => 'hourglass-half',
'signal' => 'wifi',
'snr' => 'signal',
'state' => 'bullseye',
'temperature' => 'thermometer-three-quarters',
'tv_signal' => 'signal',
'bitrate' => 'bar-chart',
'voltage' => 'bolt',
'waterflow' => 'tint',
'percent' => 'percent',
];
2018-05-09 08:05:17 -05:00
// ---- Helper Functions ----
public function classDescr()
{
$nice = collect([
'ber' => 'BER',
'dbm' => 'dBm',
'eer' => 'EER',
'snr' => 'SNR',
]);
2020-09-21 14:54:51 +02:00
2018-05-09 08:05:17 -05:00
return $nice->get($this->sensor_class, ucwords(str_replace('_', ' ', $this->sensor_class)));
}
public function icon()
{
2019-01-20 13:37:08 -06:00
return collect(self::$icons)->get($this->sensor_class, 'delicius');
}
public static function getTypes()
{
return array_keys(self::$icons);
}
2019-01-20 13:37:08 -06:00
// for the legacy menu
public static function getIconMap()
{
return self::$icons;
2018-05-09 08:05:17 -05:00
}
// ---- Define Relationships ----
public function events(): MorphMany
{
return $this->morphMany(Eventlog::class, 'events', 'type', 'reference');
}
2021-04-14 07:33:41 -05:00
public function translations(): BelongsToMany
{
return $this->belongsToMany(StateTranslation::class, 'sensors_to_state_indexes', 'sensor_id', 'state_index_id');
}
2018-05-09 08:05:17 -05:00
}