Skip to content

Commit

Permalink
fix: Types for generated services
Browse files Browse the repository at this point in the history
Related to: #512
  • Loading branch information
svrooij committed Oct 3, 2021
1 parent 4b62c24 commit 9a87007
Show file tree
Hide file tree
Showing 42 changed files with 640 additions and 338 deletions.
2 changes: 1 addition & 1 deletion .generator/node/service.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class {{serviceName}} extends Service {
* @remarks {{{remarks}}}
{{/if}}
{{#if outputs}}
* @returns {Promise<Object>} response object, with these properties {{#each outputs}}`{{name}}`{{#unless @last}}, {{/unless}}{{/each}}
* @returns {Promise<{ {{#each outputs}}{{name}}: {{relatedStateVariable.dataType}}{{#unless @last}}, {{/unless}}{{/each ~}} }>} response object.
{{else}}
* @returns {Promise<Boolean>} request succeeded
{{/if}}
Expand Down
11 changes: 5 additions & 6 deletions lib/asyncDeviceDiscovery.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
const { Sonos } = require('..')
const DeviceDiscovery = require('./deviceDiscovery')
class AsyncDeviceDiscovery {
/**
* Discover one device, will return first device found
* @param {object} options
* @param {object} options
* @param {number} options.timeout Milliseconds to timeout
* @returns {Promise<{device: Sonos, model: string}>}
* @returns {Promise<{device: import("./sonos").Sonos, model: string}>}
*/
async discover (options = { timeout: 5000 }) {
return new Promise((resolve, reject) => {
const discovery = DeviceDiscovery(options)
discovery.once('DeviceAvailable', (device, model) => {
discovery.destroy()
resolve({device, model})
resolve({ device, model })
})

discovery.once('timeout', () => {
Expand All @@ -23,9 +22,9 @@ class AsyncDeviceDiscovery {

/**
* Discover multiple devices, will return after timeout
* @param {object} options
* @param {object} options
* @param {number} options.timeout Milliseconds to timeout
* @returns {Promise<Sonos[]>}
* @returns {Promise<import("./sonos").Sonos[]>}
*/
async discoverMultiple (options = { timeout: 5000 }) {
return new Promise((resolve, reject) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/deviceDiscovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class DeviceDiscovery extends EventEmitter {
})

this.socket.on('listening', () => {
console.log('UDP port %d opened for discovery', this.socket.address().port)
// console.log('UDP port %d opened for discovery', this.socket.address().port)
this.socket.setBroadcast(true)
this.sendDiscover()
})

this.socket.bind(options.port)

if (options.timeout) {
if (options && options.timeout) {
this.searchTimer = setTimeout(() => {
this.socket.close()
this.emit('timeout')
Expand Down Expand Up @@ -117,12 +117,12 @@ class DeviceDiscovery extends EventEmitter {
const deviceDiscovery = function (options, listener = undefined) {
if (typeof options === 'function') {
listener = options
options = null
options = undefined
}
options = options || {}
listener = listener || null
listener = listener || undefined
const search = new DeviceDiscovery(options)
if (listener !== null) {
if (listener !== undefined) {
search.on('DeviceAvailable', listener)
}
return search
Expand Down
3 changes: 1 addition & 2 deletions lib/events/adv-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,12 @@ class DeviceSubscription {
if (typeof timeout === 'string') {
seconds = parseInt(((timeout.indexOf('Second-') === 0) ? timeout = timeout.substr(7) : timeout), 10)
} else {
seconds = timeout;
seconds = timeout
if (timeout < 15) {
seconds = 15
} else if (timeout > 1200) {
seconds = 1200
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class Helpers {
return ret
}

static ParseDIDLItem (item, host= undefined, port = undefined, trackUri = undefined) {
static ParseDIDLItem (item, host = undefined, port = undefined, trackUri = undefined) {
let albumArtURI = item['upnp:albumArtURI'] || null
if (albumArtURI && Array.isArray(albumArtURI)) {
albumArtURI = albumArtURI.length > 0 ? albumArtURI[0] : null
Expand Down
20 changes: 10 additions & 10 deletions lib/services/alarm-clock.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AlarmClockService extends Service {
* @param {string} options.PlayMode - Alarm play mode [ 'NORMAL' / 'REPEAT_ALL' / 'SHUFFLE_NOREPEAT' / 'SHUFFLE' ]
* @param {number} options.Volume - Volume between 0 and 100
* @param {boolean} options.IncludeLinkedZones - Should grouped players also play the alarm?
* @returns {Promise<Object>} response object, with these properties `AssignedID`
* @returns {Promise<{ AssignedID: number}>} response object.
*/
async CreateAlarm (options) { return this._request('CreateAlarm', options) }

Expand All @@ -56,13 +56,13 @@ class AlarmClockService extends Service {

/**
* GetDailyIndexRefreshTime
* @returns {Promise<Object>} response object, with these properties `CurrentDailyIndexRefreshTime`
* @returns {Promise<{ CurrentDailyIndexRefreshTime: string}>} response object.
*/
async GetDailyIndexRefreshTime () { return this._request('GetDailyIndexRefreshTime') }

/**
* GetFormat
* @returns {Promise<Object>} response object, with these properties `CurrentTimeFormat`, `CurrentDateFormat`
* @returns {Promise<{ CurrentTimeFormat: string, CurrentDateFormat: string}>} response object.
*/
async GetFormat () { return this._request('GetFormat') }

Expand All @@ -71,31 +71,31 @@ class AlarmClockService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {string} options.TimeStamp
* @returns {Promise<Object>} response object, with these properties `HouseholdUTCTime`
* @returns {Promise<{ HouseholdUTCTime: string}>} response object.
*/
async GetHouseholdTimeAtStamp (options) { return this._request('GetHouseholdTimeAtStamp', options) }

/**
* GetTimeNow
* @returns {Promise<Object>} response object, with these properties `CurrentUTCTime`, `CurrentLocalTime`, `CurrentTimeZone`, `CurrentTimeGeneration`
* @returns {Promise<{ CurrentUTCTime: string, CurrentLocalTime: string, CurrentTimeZone: string, CurrentTimeGeneration: number}>} response object.
*/
async GetTimeNow () { return this._request('GetTimeNow') }

/**
* GetTimeServer
* @returns {Promise<Object>} response object, with these properties `CurrentTimeServer`
* @returns {Promise<{ CurrentTimeServer: string}>} response object.
*/
async GetTimeServer () { return this._request('GetTimeServer') }

/**
* GetTimeZone
* @returns {Promise<Object>} response object, with these properties `Index`, `AutoAdjustDst`
* @returns {Promise<{ Index: number, AutoAdjustDst: boolean}>} response object.
*/
async GetTimeZone () { return this._request('GetTimeZone') }

/**
* GetTimeZoneAndRule
* @returns {Promise<Object>} response object, with these properties `Index`, `AutoAdjustDst`, `CurrentTimeZone`
* @returns {Promise<{ Index: number, AutoAdjustDst: boolean, CurrentTimeZone: string}>} response object.
*/
async GetTimeZoneAndRule () { return this._request('GetTimeZoneAndRule') }

Expand All @@ -104,14 +104,14 @@ class AlarmClockService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.Index
* @returns {Promise<Object>} response object, with these properties `TimeZone`
* @returns {Promise<{ TimeZone: string}>} response object.
*/
async GetTimeZoneRule (options) { return this._request('GetTimeZoneRule', options) }

/**
* ListAlarms - Get the AlarmList as XML
* @remarks Some libraries also provide a ListAndParseAlarms where the alarm list xml is parsed
* @returns {Promise<Object>} response object, with these properties `CurrentAlarmList`, `CurrentAlarmListVersion`
* @returns {Promise<{ CurrentAlarmList: string, CurrentAlarmListVersion: string}>} response object.
*/
async ListAlarms () { return this._request('ListAlarms') }

Expand Down
6 changes: 3 additions & 3 deletions lib/services/audio-in.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class AudioInService extends Service {
// #region actions
/**
* GetAudioInputAttributes
* @returns {Promise<Object>} response object, with these properties `CurrentName`, `CurrentIcon`
* @returns {Promise<{ CurrentName: string, CurrentIcon: string}>} response object.
*/
async GetAudioInputAttributes () { return this._request('GetAudioInputAttributes') }

/**
* GetLineInLevel
* @returns {Promise<Object>} response object, with these properties `CurrentLeftLineInLevel`, `CurrentRightLineInLevel`
* @returns {Promise<{ CurrentLeftLineInLevel: number, CurrentRightLineInLevel: number}>} response object.
*/
async GetLineInLevel () { return this._request('GetLineInLevel') }

Expand Down Expand Up @@ -73,7 +73,7 @@ class AudioInService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {string} options.CoordinatorID
* @returns {Promise<Object>} response object, with these properties `CurrentTransportSettings`
* @returns {Promise<{ CurrentTransportSettings: string}>} response object.
*/
async StartTransmissionToGroup (options) { return this._request('StartTransmissionToGroup', options) }

Expand Down
34 changes: 17 additions & 17 deletions lib/services/av-transport.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AVTransportService extends Service {
* @param {string} options.ContainerMetaData
* @param {number} options.DesiredFirstTrackNumberEnqueued
* @param {boolean} options.EnqueueAsNext
* @returns {Promise<Object>} response object, with these properties `FirstTrackNumberEnqueued`, `NumTracksAdded`, `NewQueueLength`, `NewUpdateID`
* @returns {Promise<{ FirstTrackNumberEnqueued: number, NumTracksAdded: number, NewQueueLength: number, NewUpdateID: number}>} response object.
*/
async AddMultipleURIsToQueue (options) { return this._request('AddMultipleURIsToQueue', options) }

Expand All @@ -54,7 +54,7 @@ class AVTransportService extends Service {
* @param {number} options.DesiredFirstTrackNumberEnqueued - use `0` to add at the end or `1` to insert at the beginning
* @param {boolean} options.EnqueueAsNext
* @remarks In NORMAL play mode the songs are added prior to the specified `DesiredFirstTrackNumberEnqueued`.
* @returns {Promise<Object>} response object, with these properties `FirstTrackNumberEnqueued`, `NumTracksAdded`, `NewQueueLength`
* @returns {Promise<{ FirstTrackNumberEnqueued: number, NumTracksAdded: number, NewQueueLength: number}>} response object.
*/
async AddURIToQueue (options) { return this._request('AddURIToQueue', options) }

Expand All @@ -68,7 +68,7 @@ class AVTransportService extends Service {
* @param {string} options.EnqueuedURI
* @param {string} options.EnqueuedURIMetaData
* @param {number} options.AddAtIndex
* @returns {Promise<Object>} response object, with these properties `NumTracksAdded`, `NewQueueLength`, `NewUpdateID`
* @returns {Promise<{ NumTracksAdded: number, NewQueueLength: number, NewUpdateID: number}>} response object.
*/
async AddURIToSavedQueue (options) { return this._request('AddURIToSavedQueue', options) }

Expand All @@ -86,7 +86,7 @@ class AVTransportService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @returns {Promise<Object>} response object, with these properties `DelegatedGroupCoordinatorID`, `NewGroupID`
* @returns {Promise<{ DelegatedGroupCoordinatorID: string, NewGroupID: string}>} response object.
*/
async BecomeCoordinatorOfStandaloneGroup (options = { InstanceID: 0 }) { return this._request('BecomeCoordinatorOfStandaloneGroup', options) }

Expand Down Expand Up @@ -174,7 +174,7 @@ class AVTransportService extends Service {
* @param {string} options.Title
* @param {string} options.EnqueuedURI
* @param {string} options.EnqueuedURIMetaData
* @returns {Promise<Object>} response object, with these properties `NumTracksAdded`, `NewQueueLength`, `AssignedObjectID`, `NewUpdateID`
* @returns {Promise<{ NumTracksAdded: number, NewQueueLength: number, AssignedObjectID: string, NewUpdateID: number}>} response object.
*/
async CreateSavedQueue (options) { return this._request('CreateSavedQueue', options) }

Expand Down Expand Up @@ -205,7 +205,7 @@ class AVTransportService extends Service {
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @remarks Send to non-coordinator may return wrong value as only the coordinator value in a group
* @returns {Promise<Object>} response object, with these properties `CrossfadeMode`
* @returns {Promise<{ CrossfadeMode: boolean}>} response object.
*/
async GetCrossfadeMode (options = { InstanceID: 0 }) { return this._request('GetCrossfadeMode', options) }

Expand All @@ -215,7 +215,7 @@ class AVTransportService extends Service {
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @remarks Send to non-coordinator returns only `Start` and `Stop` since it cannot control the stream.
* @returns {Promise<Object>} response object, with these properties `Actions`
* @returns {Promise<{ Actions: string}>} response object.
*/
async GetCurrentTransportActions (options = { InstanceID: 0 }) { return this._request('GetCurrentTransportActions', options) }

Expand All @@ -224,7 +224,7 @@ class AVTransportService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @returns {Promise<Object>} response object, with these properties `PlayMedia`, `RecMedia`, `RecQualityModes`
* @returns {Promise<{ PlayMedia: string, RecMedia: string, RecQualityModes: string}>} response object.
*/
async GetDeviceCapabilities (options = { InstanceID: 0 }) { return this._request('GetDeviceCapabilities', options) }

Expand All @@ -233,7 +233,7 @@ class AVTransportService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @returns {Promise<Object>} response object, with these properties `NrTracks`, `MediaDuration`, `CurrentURI`, `CurrentURIMetaData`, `NextURI`, `NextURIMetaData`, `PlayMedium`, `RecordMedium`, `WriteStatus`
* @returns {Promise<{ NrTracks: number, MediaDuration: string, CurrentURI: string, CurrentURIMetaData: string, NextURI: string, NextURIMetaData: string, PlayMedium: string, RecordMedium: string, WriteStatus: string}>} response object.
*/
async GetMediaInfo (options = { InstanceID: 0 }) { return this._request('GetMediaInfo', options) }

Expand All @@ -242,7 +242,7 @@ class AVTransportService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @returns {Promise<Object>} response object, with these properties `Track`, `TrackDuration`, `TrackMetaData`, `TrackURI`, `RelTime`, `AbsTime`, `RelCount`, `AbsCount`
* @returns {Promise<{ Track: number, TrackDuration: string, TrackMetaData: string, TrackURI: string, RelTime: string, AbsTime: string, RelCount: number, AbsCount: number}>} response object.
*/
async GetPositionInfo (options = { InstanceID: 0 }) { return this._request('GetPositionInfo', options) }

Expand All @@ -252,7 +252,7 @@ class AVTransportService extends Service {
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @remarks Send to non-coordinator returns error code 800
* @returns {Promise<Object>} response object, with these properties `RemainingSleepTimerDuration`, `CurrentSleepTimerGeneration`
* @returns {Promise<{ RemainingSleepTimerDuration: string, CurrentSleepTimerGeneration: number}>} response object.
*/
async GetRemainingSleepTimerDuration (options = { InstanceID: 0 }) { return this._request('GetRemainingSleepTimerDuration', options) }

Expand All @@ -261,7 +261,7 @@ class AVTransportService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @returns {Promise<Object>} response object, with these properties `AlarmID`, `GroupID`, `LoggedStartTime`
* @returns {Promise<{ AlarmID: number, GroupID: string, LoggedStartTime: string}>} response object.
*/
async GetRunningAlarmProperties (options = { InstanceID: 0 }) { return this._request('GetRunningAlarmProperties', options) }

Expand All @@ -271,7 +271,7 @@ class AVTransportService extends Service {
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @remarks Send to non-coordinator always returns PLAYING
* @returns {Promise<Object>} response object, with these properties `CurrentTransportState`, `CurrentTransportStatus`, `CurrentSpeed`
* @returns {Promise<{ CurrentTransportState: string, CurrentTransportStatus: string, CurrentSpeed: string}>} response object.
*/
async GetTransportInfo (options = { InstanceID: 0 }) { return this._request('GetTransportInfo', options) }

Expand All @@ -281,7 +281,7 @@ class AVTransportService extends Service {
* @param {Object} [options] - An object with the following properties
* @param {number} options.InstanceID - InstanceID should always be `0`
* @remarks Send to non-coordinator returns the settings of it's queue
* @returns {Promise<Object>} response object, with these properties `PlayMode`, `RecQualityMode`
* @returns {Promise<{ PlayMode: string, RecQualityMode: string}>} response object.
*/
async GetTransportSettings (options = { InstanceID: 0 }) { return this._request('GetTransportSettings', options) }

Expand Down Expand Up @@ -363,7 +363,7 @@ class AVTransportService extends Service {
* @param {number} options.UpdateID - Leave blank
* @param {number} options.StartingIndex - between 1 and queue-length
* @param {number} options.NumberOfTracks
* @returns {Promise<Object>} response object, with these properties `NewUpdateID`
* @returns {Promise<{ NewUpdateID: number}>} response object.
*/
async RemoveTrackRangeFromQueue (options) { return this._request('RemoveTrackRangeFromQueue', options) }

Expand All @@ -389,7 +389,7 @@ class AVTransportService extends Service {
* @param {number} options.UpdateID
* @param {string} options.TrackList
* @param {string} options.NewPositionList
* @returns {Promise<Object>} response object, with these properties `QueueLengthChange`, `NewQueueLength`, `NewUpdateID`
* @returns {Promise<{ QueueLengthChange: number, NewQueueLength: number, NewUpdateID: number}>} response object.
*/
async ReorderTracksInSavedQueue (options) { return this._request('ReorderTracksInSavedQueue', options) }

Expand Down Expand Up @@ -418,7 +418,7 @@ class AVTransportService extends Service {
* @param {string} options.Title - SONOS playlist title
* @param {string} options.ObjectID - Leave blank
* @remarks Send to non-coordinator returns error code 800
* @returns {Promise<Object>} response object, with these properties `AssignedObjectID`
* @returns {Promise<{ AssignedObjectID: string}>} response object.
*/
async SaveQueue (options) { return this._request('SaveQueue', options) }

Expand Down
6 changes: 3 additions & 3 deletions lib/services/connection-manager.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConnectionManagerService extends Service {
// #region actions
/**
* GetCurrentConnectionIDs
* @returns {Promise<Object>} response object, with these properties `ConnectionIDs`
* @returns {Promise<{ ConnectionIDs: string}>} response object.
*/
async GetCurrentConnectionIDs () { return this._request('GetCurrentConnectionIDs') }

Expand All @@ -38,13 +38,13 @@ class ConnectionManagerService extends Service {
*
* @param {Object} [options] - An object with the following properties
* @param {number} options.ConnectionID
* @returns {Promise<Object>} response object, with these properties `RcsID`, `AVTransportID`, `ProtocolInfo`, `PeerConnectionManager`, `PeerConnectionID`, `Direction`, `Status`
* @returns {Promise<{ RcsID: number, AVTransportID: number, ProtocolInfo: string, PeerConnectionManager: string, PeerConnectionID: number, Direction: string, Status: string}>} response object.
*/
async GetCurrentConnectionInfo (options) { return this._request('GetCurrentConnectionInfo', options) }

/**
* GetProtocolInfo
* @returns {Promise<Object>} response object, with these properties `Source`, `Sink`
* @returns {Promise<{ Source: string, Sink: string}>} response object.
*/
async GetProtocolInfo () { return this._request('GetProtocolInfo') }
// #endregion
Expand Down
Loading

0 comments on commit 9a87007

Please sign in to comment.