Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/28 #31

Merged
merged 2 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Response/Directives/GadgetController/Animations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace MaxBeckers\AmazonAlexa\Response\Directives\GadgetController;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Animations
{
/**
* @var int|null
*/
public $repeat;

/**
* @var array
*/
public $targetLights = [];

/**
* @var Sequence[]
*/
public $sequence = [];

/**
* @param int $repeat
* @param array $targetLights
* @param Sequence[] $sequence
*
* @return Parameters
*/
public static function create(int $repeat, array $targetLights = [], array $sequence = []): self
{
$animations = new self();

$animations->repeat = $repeat;
$animations->targetLights = $targetLights;
$animations->sequence = $sequence;

return $animations;
}
}
46 changes: 46 additions & 0 deletions src/Response/Directives/GadgetController/Parameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace MaxBeckers\AmazonAlexa\Response\Directives\GadgetController;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Parameters
{
const TRIGGER_EVENT_BUTTON_DOWN = 'buttonDown';
const TRIGGER_EVENT_BUTTON_UP = 'buttonUp';
const TRIGGER_EVENT_NONE = 'none';

/**
* @var string|null
*/
public $triggerEvent;

/**
* @var int|null
*/
public $triggerEventTimeMs;

/**
* @var Animations|null
*/
public $animations;

/**
* @param string $triggerEvent
* @param int $triggerEventTimeMs
* @param Animations|null $animations
*
* @return Parameters
*/
public static function create(string $triggerEvent = self::TRIGGER_EVENT_NONE, int $triggerEventTimeMs = 0, Animations $animations = null): self
{
$parameters = new self();

$parameters->triggerEvent = $triggerEvent;
$parameters->triggerEventTimeMs = $triggerEventTimeMs;
$parameters->animations = $animations;

return $parameters;
}
}
42 changes: 42 additions & 0 deletions src/Response/Directives/GadgetController/Sequence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace MaxBeckers\AmazonAlexa\Response\Directives\GadgetController;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class Sequence
{
/**
* @var int|null
*/
public $durationMs;

/**
* @var bool|null
*/
public $blend;

/**
* @var string|null
*/
public $color;

/**
* @param int $durationMs
* @param string $color
* @param bool $blend
*
* @return Parameters
*/
public static function create(int $durationMs, string $color, bool $blend = false): self
{
$animations = new self();

$animations->durationMs = $durationMs;
$animations->color = $color;
$animations->blend = $blend;

return $animations;
}
}
47 changes: 47 additions & 0 deletions src/Response/Directives/GadgetController/SetLightDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace MaxBeckers\AmazonAlexa\Response\Directives\GadgetController;

use MaxBeckers\AmazonAlexa\Response\Directives\Directive;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class SetLightDirective extends Directive
{
const TYPE = 'GadgetController.SetLight';

/**
* @var int|null
*/
public $version;

/**
* @var array
*/
public $targetGadgets = [];

/**
* @var Parameters|null
*/
public $parameters;

/**
* @param array $targetGadgets
* @param Parameters|null $parameters
* @param int $version
*
* @return SetLightDirective
*/
public static function create(array $targetGadgets = [], Parameters $parameters = null, int $version = 1): self
{
$setLight = new self();

$setLight->type = self::TYPE;
$setLight->targetGadgets = $targetGadgets;
$setLight->parameters = $parameters;
$setLight->version = $version;

return $setLight;
}
}
25 changes: 25 additions & 0 deletions test/Tests/Response/Directives/GadgetControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use MaxBeckers\AmazonAlexa\Response\Directives\GadgetController\Animations;
use MaxBeckers\AmazonAlexa\Response\Directives\GadgetController\Parameters;
use MaxBeckers\AmazonAlexa\Response\Directives\GadgetController\Sequence;
use MaxBeckers\AmazonAlexa\Response\Directives\GadgetController\SetLightDirective;
use PHPUnit\Framework\TestCase;

/**
* @author Maximilian Beckers <beckers.maximilian@gmail.com>
*/
class GadgetControllerTest extends TestCase
{
public function testSetLightDirective()
{
$sequence = Sequence::create(100, 'FF0099');
$animations = Animations::create(10, ['1'], [$sequence]);
$parameters = Parameters::create(Parameters::TRIGGER_EVENT_BUTTON_DOWN, 10, $animations);

$sl = SetLightDirective::create(['gadgetId1', 'gadgetId2'], $parameters);
$this->assertSame('GadgetController.SetLight', $sl->type);
$this->assertSame(1, $sl->version);
$this->assertSame(100, $sl->parameters->animations->sequence[0]->durationMs);
}
}