Skip to content

Commit

Permalink
Code refresh (#188)
Browse files Browse the repository at this point in the history
* fix: AudioClip notification without websockets
* chore: textual changes to templates
* chore: Workflow updates
* chore: Docs update
  • Loading branch information
svrooij authored Mar 30, 2024
1 parent 9812265 commit 40cd032
Show file tree
Hide file tree
Showing 49 changed files with 612 additions and 554 deletions.
22 changes: 22 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-18-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm install",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion .generator/ts/service-export.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* All sonos services exported as one file for easy access.
*
* Stephan van Rooij
* https://svrooij.io/sonos-api-docs
* https://sonos.svrooij.io/
*
* This file is generated, do not edit manually.
*/
Expand Down
20 changes: 10 additions & 10 deletions .generator/ts/service.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Stephan van Rooij
* https://svrooij.io
*
* This file is generated, do not edit manually. https://svrooij.io/sonos-api-docs
* This file is generated, do not edit manually. https://sonos.svrooij.io/
*/
{{#if data.importUrl}}
import { URL } from 'url';
Expand Down Expand Up @@ -70,18 +70,18 @@ export class {{serviceName}}{{#if data.extended}}Base{{/if}} extends BaseService
*/
{{/if}}
{{#if inputs}}
async {{name}}(input: { {{#each inputs}}{{name}}: {{relatedStateVariable.dataType}}{{#unless @last}}; {{/unless}}{{/each}} }{{{sonos_if_only_instance_id inputs ' = { InstanceID: 0 }'}}}):
{{name}}(input: { {{#each inputs}}{{name}}: {{relatedStateVariable.dataType}}{{#unless @last}}; {{/unless}}{{/each}} }{{{sonos_if_only_instance_id inputs ' = { InstanceID: 0 }'}}}):
{{#if outputs}}
Promise<{{name}}Response> { return await this.SoapRequestWithBody<typeof input, {{name}}Response>('{{name}}', input); }
Promise<{{name}}Response> { return this.SoapRequestWithBody<typeof input, {{name}}Response>('{{name}}', input); }
{{else}}
Promise<boolean> { return await this.SoapRequestWithBodyNoResponse<typeof input>('{{name}}', input); }
Promise<boolean> { return this.SoapRequestWithBodyNoResponse<typeof input>('{{name}}', input); }
{{/if}}
{{else}}
async {{name}}():
{{name}}():
{{#if outputs}}
Promise<{{name}}Response> { return await this.SoapRequest<{{name}}Response>('{{name}}'); }
Promise<{{name}}Response> { return this.SoapRequest<{{name}}Response>('{{name}}'); }
{{else}}
Promise<boolean> { return await this.SoapRequestNoResponse('{{name}}'); }
Promise<boolean> { return this.SoapRequestNoResponse('{{name}}'); }
{{/if}}
{{/if}}
{{#unless @last}}
Expand All @@ -91,7 +91,7 @@ export class {{serviceName}}{{#if data.extended}}Base{{/if}} extends BaseService
// #endregion
{{#if outputVariables}}

protected responseProperties(): {[key: string]: string} {
protected responseProperties(): { [key: string]: string } {
return {
{{#each outputVariables}}
{{@key}}: '{{{this}}}',
Expand All @@ -102,7 +102,7 @@ export class {{serviceName}}{{#if data.extended}}Base{{/if}} extends BaseService
{{#if eventVariables}}

// Event properties from service description.
protected eventProperties(): {[key: string]: string} {
protected eventProperties(): { [key: string]: string } {
return {
{{#each eventVariables}}
{{name}}: '{{#if (or (are_equal name 'Volume') (are_equal name 'Mute'))}}{{#if (are_equal name 'Mute')}}ChannelValue<boolean>{{else}}ChannelValue<number>{{/if}}{{else}}{{{dataType}}}{{/if}}',
Expand All @@ -112,7 +112,7 @@ export class {{serviceName}}{{#if data.extended}}Base{{/if}} extends BaseService
{{else}}

// No properties in service description, throw error on retrieval.
protected eventProperties(): {[key: string]: string} {
protected eventProperties(): { [key: string]: string } {
throw new Error('No event properties in service definition');
}
{{/if}}
Expand Down
9 changes: 4 additions & 5 deletions .generator/ts/sonos-base.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* Sonos base device with all services defined.
*
* Stephan van Rooij
* https://svrooij.io/sonos-api-docs
* https://sonos.svrooij.io/
*
* This file is generated, do not edit manually.
*/
import { Guid } from 'guid-typescript';
import debug, { Debugger } from 'debug';

import { randomUUID } from 'crypto';
import {
{{#each services}} {{name}}Service,
{{/each}}
Expand Down Expand Up @@ -40,10 +39,10 @@ export default class SonosDeviceBase {
*Creates an instance of SonosDeviceBase.
* @param {string} host The IP of the speaker
* @param {number} [port=1400] The port, always 1400
* @param {string} [uuid=Guid.create().toString()] The UUID of the speaker like RINCON_macaddres01400, used in some commands.
* @param {string} [uuid=crypto.randomUUID().toString()] The UUID of the speaker like RINCON_macaddres01400, used in some commands.
* @memberof SonosDeviceBase
*/
constructor(host: string, port = 1400, uuid: string = Guid.create().toString()) {
constructor(host: string, port = 1400, uuid: string = randomUUID().toString()) {
this.host = host;
this.port = port;
this.uuid = uuid;
Expand Down
2 changes: 1 addition & 1 deletion .generator/ts/sonos-upnp-errors.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Stephan van Rooij
* https://svrooij.io
*
* This file is generated, do not edit manually. https://svrooij.io/sonos-api-docs
* This file is generated, do not edit manually. https://sonos.svrooij.io/
*/
import { SonosUpnpError } from '../models/sonos-upnp-error';

Expand Down
2 changes: 1 addition & 1 deletion .generator/ts/template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://svrooij.io/sonos-api-docs/schema/template.json",
"$schema": "https://sonos.svrooij.io/schema/template.json",
"name": "Sonos Typescript",
"slug": "ts",
"repository": "https://github.com/svrooij/node-sonos-ts/",
Expand Down
11 changes: 7 additions & 4 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
blank_issues_enabled: true
blank_issues_enabled: false
contact_links:
- name: Sonos-ts discourd
url: https://discord.gg/VMtG6Ft36J
about: For quick answers to your questions check out our community.
- name: Documentation
url: https://sonos-ts.svrooij.io/
about: Have you checked to documentation?
- name: Questions
url: https://github.com/svrooij/node-sonos-ts/discussions/categories/q-a
about: Not sure how something works, ask a question instead of creating an issue.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -50,4 +50,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
18 changes: 9 additions & 9 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
matrix:
node: [16, 18]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

Expand Down Expand Up @@ -55,12 +55,12 @@ jobs:
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use node 16
uses: actions/setup-node@v3
- name: Use node 18
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18

- name: Install dependencies
run: npm ci
Expand All @@ -76,7 +76,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
uses: cycjimmy/semantic-release-action@v4
if: steps.mygate.outputs.inputsChecked == 'true'
id: semantic
env:
Expand All @@ -85,9 +85,9 @@ jobs:

- name: Setup node for Github Registry
if: steps.semantic.outputs.new_release_published == 'true'
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
registry-url: 'https://npm.pkg.github.com'
scope: 'svrooij'

Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[![Sonos2mqtt][badge_sonos-mqtt]][link_sonos-mqtt]
[![Sonos cli][badge_sonos-cli]][link_sonos-cli]

[![Join us on Discord][badge_discord]][link_discord]
[![Support me on Github][badge_sponsor]][link_sponsor]
[![Follow on Twitter][badge_twitter]][link_twitter]

Expand All @@ -21,7 +20,7 @@ Typescript library to control your Sonos speakers. Can be used in other typescri
---
## Key features

- [x] Auto generated client (supporting all features the normal app does). [Sonos api documentation and generator](https://svrooij.io/sonos-api-docs/)
- [x] Auto generated client (supporting all features the normal app does). [Sonos api documentation and generator][link_sonos-docs]
- [x] Auto discovery or one known device as starting point.
- [x] Support for logical devices (grouped speakers) from the start.
- [x] Access to all (generated) services.
Expand All @@ -33,11 +32,11 @@ Typescript library to control your Sonos speakers. Can be used in other typescri

To use the library just add it to your project. `npm install @svrooij/sonos`. And start using it. This library isn't meant to be used by itself, as you see in the [examples](./examples) you still need to use node (or typescript).

See **[Documentation](https://svrooij.github.io/node-sonos-ts/getting-started.html)**
See **[Documentation](https://sonos-ts.svrooij.io/getting-started.html)**

[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript] [![Join us on Discord][badge_discord]][link_discord]
[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript]

If you need help using this library, [join us on discord][link_discord].
If you need help using this library, check out the [questions section](https://github.com/svrooij/node-sonos-ts/discussions/categories/q-a) on this repository.

## Use Sonos manager (recommended)

Expand Down Expand Up @@ -118,6 +117,7 @@ sonos.PlayTTS({ text: 'Someone at the front-door', lang: 'en-US', gender: 'male'
|----|----------|----------|
|[sonos2mqtt](https://github.com/svrooij/sonos2mqtt)|[@svrooij](https://github.com/svrooij)|A bridge between sonos and mqtt, so you can control all your sonos devices right from your mqtt server|
|[sonos-cli](https://github.com/svrooij/sonos-cli)|[@svrooij](https://github.com/svrooij)|An experimental command line interface for your sonos devices.|
|[node-red-contrib-sonos-plus](https://github.com/hklages/node-red-contrib-sonos-plus)|[@hklages](https://github.com/hklages)|A node-red node to control your sonos devices|

Also using this library, but not in the list? Send a PR.

Expand All @@ -127,7 +127,6 @@ Also using this library, but not in the list? Send a PR.
[![Sonos2mqtt][badge_sonos-mqtt]][link_sonos-mqtt]
[![Sonos cli][badge_sonos-cli]][link_sonos-cli]
[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript]
[![Join us on Discord][badge_discord]][link_discord]
[![Support me on Github][badge_sponsor]][link_sponsor]
[![Follow on Twitter][badge_twitter]][link_twitter]

Expand Down Expand Up @@ -198,7 +197,6 @@ Creating a library from scratch is quite hard, and I'm using a lot of stuff from
[badge_build]: https://img.shields.io/github/actions/workflow/status/svrooij/node-sonos-ts/test-and-release.yml?branch=beta&style=for-the-badge
[badge_contrib]: https://img.shields.io/github/all-contributors/svrooij/node-sonos-ts?style=for-the-badge
[badge_coverage]: https://img.shields.io/coverallsCoverage/github/svrooij/node-sonos-ts?style=for-the-badge&branch=beta
[badge_discord]: https://img.shields.io/discord/782374564054564875?style=for-the-badge
[badge_issues]: https://img.shields.io/github/issues/svrooij/node-sonos-ts?style=for-the-badge
[badge_npm]: https://img.shields.io/npm/v/@svrooij/sonos?style=for-the-badge
[badge_sonos-cli]: https://img.shields.io/badge/sonos-cli-blue?style=for-the-badge
Expand All @@ -209,12 +207,11 @@ Creating a library from scratch is quite hard, and I'm using a lot of stuff from
[badge_twitter]: https://img.shields.io/twitter/follow/svrooij?logo=twitter&style=for-the-badge

[link_build]: https://github.com/svrooij/node-sonos-ts/actions
[link_discord]: https://discord.gg/VMtG6Ft36J
[link_issues]: https://github.com/svrooij/node-sonos-ts/issues
[link_npm]: https://www.npmjs.com/package/@svrooij/sonos
[link_sonos-cli]: https://github.com/svrooij/sonos-cli
[link_sonos-docs]: https://svrooij.io/sonos-api-docs
[link_sonos-mqtt]: https://svrooij.io/sonos2mqtt
[link_sonos-typescript]: https://svrooij.io/node-sonos-ts
[link_sonos-docs]: https://sonos.svrooij.io/
[link_sonos-mqtt]: https://sonos2mqtt.svrooij.io/
[link_sonos-typescript]: https://sonos-ts.svrooij.io/
[link_sponsor]: https://github.com/sponsors/svrooij
[link_twitter]: https://twitter.com/svrooij
14 changes: 5 additions & 9 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ permalink: /
[![Sonos cli][badge_sonos-cli]][link_sonos-cli]
[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript]

[![Join us on Discord][badge_discord]][link_discord]
[![Support me on Github][badge_sponsor]][link_sponsor]
[![Follow on Twitter][badge_twitter]][link_twitter]

Expand All @@ -31,7 +30,7 @@ This library is in no way connected to [Sonos](//en.wikipedia.org/wiki/Sonos).

## Key features

- [x] Auto generated client (supporting all features the normal app does). [Sonos api documentation and generator](https://svrooij.io/sonos-api-docs/)
- [x] Auto generated client (supporting all features the normal app does). [Sonos api documentation and generator][link_sonos-docs]
- [x] Auto discovery or one known device as starting point.
- [x] Support for logical devices (grouped speakers) from the start.
- [x] Access to all (generated) services.
Expand All @@ -43,10 +42,9 @@ This library is in no way connected to [Sonos](//en.wikipedia.org/wiki/Sonos).

To use the library just add it to your project. `npm install @svrooij/sonos`. And start using it. This library isn't meant to be used by itself, as you see in the [examples](https://github.com/svrooij/node-sonos-ts/tree/master/examples) you still need to use node (or typescript).

See **[Documentation](https://svrooij.github.io/node-sonos-ts/getting-started.html)**
See **[Documentation](https://sonos-ts.svrooij.io/getting-started.html)**

[![Sonos typescript this library][badge_sonos-typescript]][link_sonos-typescript]
[![Join us on Discord][badge_discord]][link_discord]

## Packages using sonos-ts

Expand Down Expand Up @@ -95,7 +93,6 @@ specification. Contributions of any kind welcome!
[badge_build]: https://img.shields.io/github/actions/workflow/status/svrooij/node-sonos-ts/test-and-release.yml?branch=beta&style=for-the-badge
[badge_contrib]: https://img.shields.io/github/all-contributors/svrooij/node-sonos-ts?style=for-the-badge
[badge_coverage]: https://img.shields.io/coverallsCoverage/github/svrooij/node-sonos-ts?style=for-the-badge&branch=beta
[badge_discord]: https://img.shields.io/discord/782374564054564875?style=for-the-badge
[badge_issues]: https://img.shields.io/github/issues/svrooij/node-sonos-ts?style=for-the-badge
[badge_npm]: https://img.shields.io/npm/v/@svrooij/sonos?style=for-the-badge
[badge_sonos-cli]: https://img.shields.io/badge/sonos-cli-blue?style=for-the-badge
Expand All @@ -106,12 +103,11 @@ specification. Contributions of any kind welcome!
[badge_twitter]: https://img.shields.io/twitter/follow/svrooij?logo=twitter&style=for-the-badge

[link_build]: https://github.com/svrooij/node-sonos-ts/actions
[link_discord]: https://discord.gg/VMtG6Ft36J
[link_issues]: https://github.com/svrooij/node-sonos-ts/issues
[link_npm]: https://www.npmjs.com/package/@svrooij/sonos
[link_sonos-cli]: https://github.com/svrooij/sonos-cli
[link_sonos-docs]: https://svrooij.io/sonos-api-docs
[link_sonos-mqtt]: https://svrooij.io/sonos2mqtt
[link_sonos-typescript]: https://svrooij.io/node-sonos-ts
[link_sonos-docs]: https://sonos.svrooij.io/
[link_sonos-mqtt]: https://sonos2mqtt.svrooij.io/
[link_sonos-typescript]: https://sonos-ts.svrooij.io/
[link_sponsor]: https://github.com/sponsors/svrooij
[link_twitter]: https://twitter.com/svrooij
2 changes: 1 addition & 1 deletion docs/sonos-device/services/alarm-clock-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ grand_parent: Sonos device

Control the sonos alarms and times

The AlarmClock service is available on these models: `v2-S1` / `v2-S13` / `v2-S14` / `v2-S18` / `v2-S21` / `v2-S27` / `v2-S3` / `v2-S6` / `v2-S9` / `v2-Sub`.
The AlarmClock service is available on these models: `v2-S1` / `v2-S13` / `v2-S14` / `v2-S18` / `v2-S21` / `v2-S27` / `v2-S3` / `v2-S33` / `v2-S38` / `v2-S6` / `v2-S9` / `v2-Sub`.

```js
const SonosDevice = require('@svrooij/sonos').SonosDevice
Expand Down
4 changes: 2 additions & 2 deletions docs/sonos-device/services/av-transport-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ grand_parent: Sonos device
# AVTransport service
{: .no_toc }

Service that controls stuff related to transport (play/pause/next/special urls)
Service that controls stuff related to transport (play/pause/next/special URLs)

The AVTransport service is available on these models: `v2-S1` / `v2-S13` / `v2-S14` / `v2-S18` / `v2-S21` / `v2-S27` / `v2-S3` / `v2-S6` / `v2-S9` / `v2-Sub`.
The AVTransport service is available on these models: `v2-S1` / `v2-S13` / `v2-S14` / `v2-S18` / `v2-S21` / `v2-S27` / `v2-S3` / `v2-S33` / `v2-S38` / `v2-S6` / `v2-S9` / `v2-Sub`.

```js
const SonosDevice = require('@svrooij/sonos').SonosDevice
Expand Down
2 changes: 1 addition & 1 deletion docs/sonos-device/services/connection-manager-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ grand_parent: Sonos device

Services related to connections and protocols

The ConnectionManager service is available on these models: `v2-S1` / `v2-S13` / `v2-S14` / `v2-S18` / `v2-S21` / `v2-S27` / `v2-S3` / `v2-S6` / `v2-S9` / `v2-Sub`.
The ConnectionManager service is available on these models: `v2-S1` / `v2-S13` / `v2-S14` / `v2-S18` / `v2-S21` / `v2-S27` / `v2-S3` / `v2-S33` / `v2-S38` / `v2-S6` / `v2-S9` / `v2-Sub`.

```js
const SonosDevice = require('@svrooij/sonos').SonosDevice
Expand Down
Loading

0 comments on commit 40cd032

Please sign in to comment.