Skip to content

Commit

Permalink
feat: Merge pull request #85 from seamapi/feat-connected-accounts-update
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb authored Dec 12, 2023
2 parents 8fdbc34 + 845a9b4 commit 595e631
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Objects/ConnectedAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function from_json(mixed $json): ConnectedAccount|null
fn ($e) => SeamWarning::from_json($e),
$json->warnings ?? []
),
automatically_manage_new_devices: $json->automatically_manage_new_devices
);
}

Expand All @@ -35,7 +36,8 @@ public function __construct(
public array $errors,
public array $warnings,
public string $created_at,
public mixed $custom_metadata
public mixed $custom_metadata,
public bool $automatically_manage_new_devices
) {
}
}
21 changes: 18 additions & 3 deletions src/SeamClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,14 @@ public function create(

/**
* Create Access Codes across multiple Devices that share a common code
*
*
* @param string[] $device_ids
* @param string|null $name
* @param string|null $starts_at
* @param string|null $ends_at
* @param string|null $behavior_when_code_cannot_be_shared Accepts either "throw" or "create_random_code"
* @param bool|null $attempt_for_offline_device
*
*
* @return AccessCode[]
*/
public function create_multiple(
Expand Down Expand Up @@ -883,6 +883,21 @@ public function get(string $connected_account_id): ConnectedAccount
)
);
}

public function update(string $connected_account_id, bool $automatically_manage_new_devices): ConnectedAccount
{
return ConnectedAccount::from_json(
$this->seam->request(
"POST",
"connected_accounts/update",
json: [
"connected_account_id" => $connected_account_id,
"automatically_manage_new_devices" => $automatically_manage_new_devices,
],
inner_object: "connected_account"
)
);
}
}

class EventsClient
Expand Down Expand Up @@ -1245,7 +1260,7 @@ class ThermostatsClient
{
private SeamClient $seam;


public ClimateSettingSchedulesClient $climate_setting_schedules;

public function __construct(SeamClient $seam)
Expand Down
27 changes: 27 additions & 0 deletions tests/ConnectedAccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,31 @@ public function testDeleteConnectedAccount(): void
$this->assertTrue(str_contains($exception->getMessage(), "connected_account_not_found"));
}
}

public function testUpdateConnectedAccount(): void
{
$seam = Fixture::getTestServer(true);
$connected_accounts = $seam->connected_accounts->list();

$connected_account_id = $connected_accounts[0]->connected_account_id;

$connected_account = $seam->connected_accounts->get(
connected_account_id: $connected_account_id
);
$this->assertTrue(
$connected_account->automatically_manage_new_devices === true
);

$seam->connected_accounts->update(
connected_account_id: $connected_account_id,
automatically_manage_new_devices: false
);

$connected_account = $seam->connected_accounts->get(
connected_account_id: $connected_account_id
);
$this->assertTrue(
$connected_account->automatically_manage_new_devices === false
);
}
}

0 comments on commit 595e631

Please sign in to comment.