diff options
Diffstat (limited to 'localwebsite/classes')
-rw-r--r-- | localwebsite/classes/TemphumdClient.php (renamed from localwebsite/classes/Si7021dClient.php) | 14 | ||||
-rw-r--r-- | localwebsite/classes/config.php | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/localwebsite/classes/Si7021dClient.php b/localwebsite/classes/TemphumdClient.php index b976448..07e5a3e 100644 --- a/localwebsite/classes/Si7021dClient.php +++ b/localwebsite/classes/TemphumdClient.php @@ -1,17 +1,19 @@ <?php -class Si7021dClient extends MySimpleSocketClient { +class TemphumdClient extends MySimpleSocketClient { public string $name; public float $temp; public float $humidity; + public ?int $flags; /** * @throws Exception */ - public function __construct(string $host, int $port, string $name) { + public function __construct(string $host, int $port, string $name, ?int $flags = null) { parent::__construct($host, $port); $this->name = $name; + $this->flags = $flags; socket_set_timeout($this->sock, 3); } @@ -28,4 +30,12 @@ class Si7021dClient extends MySimpleSocketClient { $this->humidity = $hum; } + public function hasTemperature(): bool { + return ($this->flags & config::TEMPHUMD_NO_TEMP) == 0; + } + + public function hasHumidity(): bool { + return ($this->flags & config::TEMPHUMD_NO_HUM) == 0; + } + }
\ No newline at end of file diff --git a/localwebsite/classes/config.php b/localwebsite/classes/config.php index 87ecf1c..927321e 100644 --- a/localwebsite/classes/config.php +++ b/localwebsite/classes/config.php @@ -2,6 +2,9 @@ class config { + const TEMPHUMD_NO_TEMP = 1 << 0; + const TEMPHUMD_NO_HUM = 1 << 1; + public static function get(string $key) { global $config; return is_callable($config[$key]) ? $config[$key]() : $config[$key]; |