From a34a44dbdea30028729bd1768a1a3aafa39bc567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Fri, 13 Oct 2017 19:59:45 +0200 Subject: [PATCH] Shut & reveal actions --- backend/models/scene/SceneExecutor.php | 2 +- backend/models/supla/SuplaApi.php | 4 ++++ backend/models/supla/SuplaApiCached.php | 15 ++++++++++++++- backend/models/supla/SuplaApiReadOnly.php | 18 ++++++++++++++++-- backend/models/supla/SuplaApiReal.php | 10 ++++++++++ .../channel/channel-available-actions.coffee | 4 ++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/backend/models/scene/SceneExecutor.php b/backend/models/scene/SceneExecutor.php index 5f1f1f1d..a10a4ba6 100644 --- a/backend/models/scene/SceneExecutor.php +++ b/backend/models/scene/SceneExecutor.php @@ -19,7 +19,7 @@ public function executeCommandFromString($command) list($channelId, $action) = explode(self::CHANNEL_DELIMITER, $command); $args = explode(self::ARGUMENT_DELIMITER, $action); $action = array_shift($args); - Assertion::inArray($action, ['turnOn', 'turnOff', 'toggle', 'getChannelState', 'setRgb']); + Assertion::inArray($action, ['turnOn', 'turnOff', 'toggle', 'getChannelState', 'setRgb', 'shut', 'reveal']); array_unshift($args, $channelId); $this->getApi()->clearCache($channelId); return call_user_func_array([$this->getApi(), $action], $args); diff --git a/backend/models/supla/SuplaApi.php b/backend/models/supla/SuplaApi.php index 4e8f7623..da14e331 100644 --- a/backend/models/supla/SuplaApi.php +++ b/backend/models/supla/SuplaApi.php @@ -40,6 +40,10 @@ public abstract function getSensorLogs(int $channelId, $fromTime = '-1day'): arr public abstract function getClient(): SuplaApiClient; + public abstract function shut(int $channelId, int $percent = 100); + + public abstract function reveal(int $channelId, int $percent = 100); + public function clearCache($channelId = null) { } diff --git a/backend/models/supla/SuplaApiCached.php b/backend/models/supla/SuplaApiCached.php index 73ad27bb..549ed2ed 100644 --- a/backend/models/supla/SuplaApiCached.php +++ b/backend/models/supla/SuplaApiCached.php @@ -71,6 +71,18 @@ public function getSensorLogs(int $channelId, $fromTime = '-1day'): array return $this->api->getSensorLogs($channelId, $fromTime); } + public function shut(int $channelId, int $percent = 100) + { + $this->clearCache($channelId); + return $this->api->shut($channelId, $percent); + } + + public function reveal(int $channelId, int $percent = 100) + { + $this->clearCache($channelId); + return $this->api->reveal($channelId, $percent); + } + public function getClient(): SuplaApiClient { return $this->api->getClient(); @@ -88,7 +100,8 @@ private function getFromCache($method, array $arguments, callable $factory, $cha return $value; } - public function clearCache($channelId = null) { + public function clearCache($channelId = null) + { $group = $this->user->id . ($channelId ? '/' . $channelId : ''); \FileSystemCache::invalidateGroup($group); } diff --git a/backend/models/supla/SuplaApiReadOnly.php b/backend/models/supla/SuplaApiReadOnly.php index 5709e460..2244a2b5 100644 --- a/backend/models/supla/SuplaApiReadOnly.php +++ b/backend/models/supla/SuplaApiReadOnly.php @@ -34,11 +34,25 @@ public function turnOff(int $channelId) public function setRgb(int $channelId, string $color, int $colorBrightness = 100, int $brightness = 100) { - return parent::setRgb($channelId, $color, $colorBrightness, $brightness); // TODO: Change the autogenerated stub + $this->logger->info('READ-ONLY: Set RGB: ' . $channelId); + return true; } public function toggle(int $channelId) { - return parent::toggle($channelId); // TODO: Change the autogenerated stub + $this->logger->info('READ-ONLY: Toggle: ' . $channelId); + return true; + } + + public function shut(int $channelId, int $percent = 100) + { + $this->logger->info('READ-ONLY: Shut: ' . $channelId); + return true; + } + + public function reveal(int $channelId, int $percent = 100) + { + $this->logger->info('READ-ONLY: Reveal: ' . $channelId); + return true; } } diff --git a/backend/models/supla/SuplaApiReal.php b/backend/models/supla/SuplaApiReal.php index f966f878..7d120a1c 100644 --- a/backend/models/supla/SuplaApiReal.php +++ b/backend/models/supla/SuplaApiReal.php @@ -121,6 +121,16 @@ public function getSensorLogs(int $channelId, $fromTime = '-1day'): array return $result; } + public function shut(int $channelId, int $percent = 100) + { + return $this->client->channelShut($channelId, $percent); + } + + public function reveal(int $channelId, int $percent = 100) + { + return $this->client->channelReveal($channelId, $percent); + } + private function handleError($response) { if (!$response) { diff --git a/frontend/app/dashboard/channel/channel-available-actions.coffee b/frontend/app/dashboard/channel/channel-available-actions.coffee index 43959f24..f10dd4eb 100644 --- a/frontend/app/dashboard/channel/channel-available-actions.coffee +++ b/frontend/app/dashboard/channel/channel-available-actions.coffee @@ -22,6 +22,10 @@ angular.module('supla-scripts').constant 'CHANNEL_AVAILABLE_ACTIONS', do -> {label: 'różowy', action: 'setRgb,00ffff,0,0', noButton: yes, isActive: -> no} {label: 'zielony', action: 'setRgb,00ff00,0,0', noButton: yes, isActive: -> no} ] + FNC_CONTROLLINGTHEROLLERSHUTTER: [ + {label: 'odsłoń', action: 'reveal', isActive: -> no} + {label: 'zasłoń', action: 'shut', isActive: -> no} + ] actions.FNC_LIGHTSWITCH = actions.FNC_POWERSWITCH actions.FNC_CONTROLLINGTHEGARAGEDOOR = actions.FNC_CONTROLLINGTHEGATE