Files
zigbee_card/lib/Buttons.php

52 lines
2.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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 -- except the feeder (one action, behind a second tap; the line under it is when Bella
* was last fed) and 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']],
['key' => 'feed', 'kind' => 'action', 'icon' => '🐾', 'label' => 'feed bella', 'now' => 'one portion · asks twice', 'send' => 'feed bella', 'confirm' => true],
];
/** 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',
'feed bella',
'state',
];
public static function allowed(string $line): bool {
return in_array($line, self::LINES, true);
}
}