58 lines
3.6 KiB
PHP
58 lines
3.6 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
namespace OCA\ZigbeeCard;
|
||
|
||
/**
|
||
* The card: six rows, drawn like every other dashboard card's list (icon, title, a line
|
||
* under it). Each row is a TOGGLE drawn from the bot's "state" read -- the title is the
|
||
* ACTION a press takes ("day" when the room is on night) and the line under it says what
|
||
* is -- the 📺 TV too (2026-10-27, it replaced the feeder row; feeding is a DM now) -- except the climate row (a reading: temp · humidity · feedings in 24 h,
|
||
* the door's last change under it; pressing it refreshes). The JS gets this list as initial state; the controller
|
||
* refuses any line that is not in LINES, so the page cannot be talked into sending
|
||
* anything else.
|
||
*
|
||
* Every line is a command the house bot already understands verbatim in a chat DM. The
|
||
* bot's door carries its own allow-list, so a line has to pass both before a device
|
||
* hears it. Scenes are called BY NAME: where a scene lives is the bot's business.
|
||
*/
|
||
final class Buttons {
|
||
/**
|
||
* key: the state field the toggle reads ('ac'/'heater' read state.plugs)
|
||
* on/off: when the state equals `when`: the title (the action), `now` (the line under
|
||
* it, what is) and `send` (the line a press posts)
|
||
* @var array<int, array<string, mixed>>
|
||
*/
|
||
public const ALL = [
|
||
['key' => 'climate', 'kind' => 'reading', 'icon' => '🌡', 'now' => 'asking the house'], // until the first state: then the door's last change (js)
|
||
['key' => 'scene', 'kind' => 'cycle', 'icon' => '🎬', 'label' => 'scene', 'now' => 'tap to cycle scenes', 'send' => 'lights next'],
|
||
['key' => 'dimmer', 'kind' => 'dimmer', 'icon' => '🔆', 'label' => 'dim', 'now' => 'tap −10% · hold = off', 'send' => 'lights dim', 'hold' => 'lights off'],
|
||
['key' => 'ac', 'kind' => 'toggle', 'icon' => '❄️',
|
||
'on' => ['when' => 'ON', 'label' => 'AC off', 'now' => 'AC is on', 'send' => 'ac off'],
|
||
'off' => ['when' => 'OFF', 'label' => 'AC on', 'now' => 'AC is off', 'send' => 'ac on']],
|
||
['key' => 'heater', 'kind' => 'toggle', 'icon' => '🔥',
|
||
'on' => ['when' => 'ON', 'label' => 'bathroom heater off', 'now' => 'bathroom heater is on', 'send' => 'heater off'],
|
||
'off' => ['when' => 'OFF', 'label' => 'bathroom heater on', 'now' => 'bathroom heater is off', 'send' => 'heater on']],
|
||
// 2026-10-27 (Brock: "change zigbee card last entry from bellas feeder to tv on", then "just call it display"): the display, a Fire TV
|
||
// Omni over srv's Bluetooth radio -- power on and HDMI 4 in one press (ops/psn-docker apps/firetv).
|
||
// A TOGGLE like ac/heater (Brock: "EXACT SAME PATTERN AS THE REST OF THE CARD TOGGLE"): it reads
|
||
// state.plugs.tv = the power state the keyboard last set (the TV reports nothing back).
|
||
// `tv on` = Wake + HDMI 4, `tv off` = Sleep; both idempotent. Feeding Bella stays a DM.
|
||
['key' => 'tv', 'kind' => 'toggle', 'icon' => '📺',
|
||
'on' => ['when' => 'ON', 'label' => 'display off', 'now' => 'display is on', 'send' => 'display off'],
|
||
'off' => ['when' => 'OFF', 'label' => 'display on', 'now' => 'display is off', 'send' => 'display on']],
|
||
];
|
||
|
||
/** Every line the page may send: the toggles' two sides, the action, and the one read. */
|
||
public const LINES = [
|
||
'lights day', 'lights night', 'lights on', 'lights off', 'lights next', 'lights dim',
|
||
'ac on', 'ac off', 'heater on', 'heater off',
|
||
'display on', 'display off',
|
||
'state',
|
||
];
|
||
|
||
public static function allowed(string $line): bool {
|
||
return in_array($line, self::LINES, true);
|
||
}
|
||
}
|