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;
|
2021-03-31 17:28:47 +02:00
|
|
|
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;
|
2018-10-08 20:57:12 +02:00
|
|
|
protected $primaryKey = 'sensor_id';
|
2020-04-19 19:57:49 +02:00
|
|
|
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',
|
2020-04-19 19:57:49 +02:00
|
|
|
'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',
|
2020-05-31 01:24:43 +02:00
|
|
|
'loss' => 'percentage',
|
2020-04-19 19:57:49 +02:00
|
|
|
'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',
|
2021-01-03 23:35:32 +02:00
|
|
|
'tv_signal' => 'signal',
|
2020-04-19 19:57:49 +02:00
|
|
|
'voltage' => 'bolt',
|
|
|
|
'waterflow' => 'tint',
|
2020-10-20 17:11:12 -07:00
|
|
|
'percent' => 'percent',
|
2020-04-19 19:57:49 +02:00
|
|
|
];
|
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');
|
|
|
|
}
|
|
|
|
|
2020-04-19 19:57:49 +02:00
|
|
|
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 ----
|
2021-03-31 17:28:47 +02:00
|
|
|
public function events(): MorphMany
|
2018-09-24 02:07:00 -05:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|