Skip to content

Commit

Permalink
Merge branch 'main' into Samsung_AudioNotification_HCS5008
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandblue authored Aug 9, 2024
2 parents b50e387 + 33f7376 commit d55a9a2
Show file tree
Hide file tree
Showing 187 changed files with 7,457 additions and 1,734 deletions.
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Check all that apply

# Type of Change

- [ ] WWST Certification Request
- If this is your first time contributing code:
- [ ] I have reviewed the README.md file
- [ ] I have reviewed the CODE_OF_CONDUCT.md file
- [ ] I have signed the CLA
- [ ] I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
- [ ] Bug fix
- [ ] New feature
- [ ] Refactor

# Checklist

- [ ] I have performed a self-review of my code
- [ ] I have commented my code in hard-to-understand areas
- [ ] I have verified my changes by testing with a device or have communicated a plan for testing
- [ ] I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior

# Description of Change


# Summary of Completed Tests


2 changes: 0 additions & 2 deletions drivers/SmartThings/harman-luxury/profiles/harman-luxury.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ components:
version: 1
- id: audioNotification
version: 1
- id: keypadInput
version: 1
- id: refresh
version: 1
categories:
Expand Down
2 changes: 0 additions & 2 deletions drivers/SmartThings/harman-luxury/profiles/maX10.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ components:
version: 1
- id: audioTrackData
version: 1
- id: mediaPresets
version: 1
- id: mediaPlayback
version: 1
- id: mediaTrackControl
Expand Down
266 changes: 17 additions & 249 deletions drivers/SmartThings/harman-luxury/src/api/apis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ local invoke = require "api.invokes"

--- system paths -----------------------------------------

local UUID_PATH = "settings:/system/memberId"
local MAC_PATH = "settings:/system/primaryMacAddress"
local MEMBER_ID_PATH = "settings:/system/memberId"
local MANUFACTURER_NAME_PATH = "settings:/system/manufacturer"
local DEVICE_NAME_PATH = "settings:/deviceName"
local MODEL_NAME_PATH = "settings:/system/modelName"
local PRODUCT_NAME_PATH = "settings:/system/productName"

--- SmartThings paths ----------------------------------
local SMARTTHINGS_PATH = "smartthings:"
local SMARTTHINGS_AUDIO_PATH = "smartthings:audio/"
local SMARTTHINGS_MEDIA_PATH = "smartthings:media/"
local INIT_CREDENTIAL_PATH = "smartthings:initCredentialsToken"
local CREDENTIAL_PATH = "settings:/smartthings/userToken"

----------------------------------------------------------
--- APIs
Expand All @@ -29,27 +23,6 @@ local APIs = {}

--- system APIs ------------------------------------------

--- get UUID from Harman Luxury on ip
---@param ip string
---@return string|nil, nil|string
function APIs.GetUUID(ip)
return get.String(ip, UUID_PATH)
end

--- get MAC address from Harman Luxury on ip
---@param ip string
---@return string|nil, nil|string
function APIs.GetMAC(ip)
return get.String(ip, MAC_PATH)
end

--- get Member ID from Harman Luxury on ip
---@param ip string
---@return string|nil, nil|string
function APIs.GetMemberId(ip)
return get.String(ip, MEMBER_ID_PATH)
end

--- get device manufacturer name from Harman Luxury on ip
---@param ip string
---@return string|nil, nil|string
Expand Down Expand Up @@ -86,233 +59,28 @@ function APIs.SetDeviceName(ip, value)
return set.String(ip, DEVICE_NAME_PATH, value)
end

--- get active credential token from a Harman Luxury device on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.InitCredentialsToken(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "initCredentialsToken")
end

--- get active credential token from a Harman Luxury device on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.GetCredentialsToken(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "getCredentialsToken")
end

--- get supported input sources from a Harman Luxury device on ip
--- initialise a new credential token from Harman Luxury on ip
---@param ip string
---@return table|nil, nil|string
function APIs.GetSupportedInputSources(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "getSupportedInputSources")
end

--- power manager APIs -----------------------------------

--- invoke smartthings:setOn on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.SetOn(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "setOn")
end

--- invoke smartthings:setOff on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.SetOff(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "setOff")
end

--- get current power state Harman Luxury on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.GetPowerState(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "powerStatus")
end

--- audio APIs ------------------------------------

--- set Mute value of Harman Luxury media player on ip
---@param ip string
---@param value boolean
---@return boolean|number|string|table|nil, nil|string
function APIs.SetMute(ip, value)
return set.Bool(ip, SMARTTHINGS_AUDIO_PATH .. "mute", value)
end

--- get Mute value of Harman Luxury media player on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.GetMute(ip)
return get.Bool(ip, SMARTTHINGS_AUDIO_PATH .. "mute")
end

--- set Volume value of Harman Luxury media player on ip
---@param ip string
---@param value integer
---@return boolean|number|string|table|nil, nil|string
function APIs.SetVol(ip, value)
return set.I32(ip, SMARTTHINGS_AUDIO_PATH .. "volume", value)
end

--- get Volume value of Harman Luxury media player on ip
---@param ip string
---@return number|nil, nil|string
function APIs.GetVol(ip)
return get.I32(ip, SMARTTHINGS_AUDIO_PATH .. "volume")
end

--- invoke smartthings:audio/getAudioTrackData on ip
---@class AudioTrackData
---@field trackdata table<string>
---@field supportedPlaybackCommands table<string>
---@field supportedTrackControlCommands table<string>
---@field totalTime number
---@param ip string
---@return AudioTrackData|nil, nil|string
function APIs.getAudioTrackData(ip)
local val, err = invoke.Activate(ip, SMARTTHINGS_AUDIO_PATH .. "getAudioTrackData")
if val then
local audioTrackData = {
trackdata = {
title = val.title or "",
artist = val.artist or nil,
album = val.album or nil,
albumArtUrl = val.albumArtUrl or nil,
mediaSource = val.mediaSource or nil,
},
supportedPlaybackCommands = val.supportedPlaybackCommands,
supportedTrackControlCommands = val.supportedTrackControlCommands,
totalTime = val.totalTime,
}
return audioTrackData, nil
else
---@return string|nil, nil|string
function APIs.init_credential_token(ip)
local val, err = invoke.Activate(ip, INIT_CREDENTIAL_PATH)
if err then
return nil, err
end
end

--- Audio Notification API ------------------------------------

--- invoke Audio Notification of Harman Luxury on ip
---@param ip string
---@param uri string
---@param level number
---@return boolean|number|string|table|nil, nil|string
function APIs.SendAudioNotification(ip, uri, level)
local value = {
smartthingsAudioNotification = {
uri = uri,
level = level,
},
}
return invoke.ActivateValue(ip, SMARTTHINGS_PATH .. "playAudioNotification", value)
end

--- media player APIs ------------------------------------

--- set Input Source value of Harman Luxury on ip
---@param ip string
---@param source string
---@return boolean|number|string|table|nil, nil|string
function APIs.SetInputSource(ip, source)
local value = {
string_ = source,
}
return invoke.ActivateValue(ip, SMARTTHINGS_MEDIA_PATH .. "setInputSource", value)
end

--- get Input Source value of Harman Luxury on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.GetInputSource(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "getInputSource")
end

--- play Media Preset with given id value on Harman Luxury on ip
---@param ip string
---@param id integer
---@return boolean|number|string|table|nil, nil|string
function APIs.PlayMediaPreset(ip, id)
local value = {
i32_ = id,
}
return invoke.ActivateValue(ip, SMARTTHINGS_MEDIA_PATH .. "playMediaPreset", value)
end

--- get Media Preset list of Harman Luxury on ip
---@param ip string
---@return table|nil, nil|string
function APIs.GetMediaPresets(ip)
local val, err = invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "getMediaPresets")
if val then
return val.presets, nil
else
return nil, err
if type(val) == "string" then
return val, nil
else
err = string.format("Device with IP:%s failed to generate a valid credential", ip)
return nil, err
end
end
end

--- invoke smartthings:media/setPlay on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.InvokePlay(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "setPlay")
end

--- invoke smartthings:media/setPause on ip
--- get device current active token from Harman Luxury on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.InvokePause(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "setPause")
end

--- invoke smartthings:media/setNextTrack on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.InvokeNext(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "setNextTrack")
end

--- invoke smartthings:media/setPrevTrack on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.InvokePrevious(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "setPrevTrack")
end

--- invoke smartthings:media/setStop on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.InvokeStop(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "setStop")
end

--- invoke smartthings:media/setStop on ip
---@param ip string
---@return boolean|number|string|table|nil, nil|string
function APIs.GetPlayerState(ip)
return invoke.Activate(ip, SMARTTHINGS_MEDIA_PATH .. "getPlayerState")
end

--- key input APIs ------------------------------------

--- invoke smartthings:sendKey on ip
---@param ip string
---@param key string
---@return boolean|number|string|table|nil, nil|string
function APIs.InvokeSendKey(ip, key)
local value = {
NsdkSmartThingsKey = key,
}
return invoke.ActivateValue(ip, SMARTTHINGS_PATH .. "sendKey", value)
end

--- check for values change APIs ------------------------------------

--- invoke smartthings:updateValues on ip
---@param ip string
---@return table|nil, nil|string
function APIs.InvokeGetUpdates(ip)
return invoke.Activate(ip, SMARTTHINGS_PATH .. "updateValues")
---@return string|nil, nil|string
function APIs.GetActiveCredentialToken(ip)
return get.String(ip, CREDENTIAL_PATH)
end

return APIs
9 changes: 7 additions & 2 deletions drivers/SmartThings/harman-luxury/src/api/nsdk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
---@param func_name string
---@param u string
---@param sink string
---@param code integer
---@param code integer|string
---@param valLocationFunc function
---@return boolean|number|string|table|nil, nil|string
local function handleReply(func_name, u, sink, code, valLocationFunc)
Expand All @@ -88,7 +88,12 @@ local function handleReply(func_name, u, sink, code, valLocationFunc)
end
return nil, err
else -- UNKNOWN VALUE
local err = string.format("Error in %s: Unknown return value: code: %s, sink: %s", func_name, code, sink)
local err
if string.find(code, "timeout") then
err = string.format("Error in %s: Connection timeout", func_name)
else
err = string.format("Error in %s: Unknown return value: code: %s, sink: %s", func_name, code, sink)
end
log.error(err)
return nil, err
end
Expand Down
Loading

0 comments on commit d55a9a2

Please sign in to comment.