diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index c3c80e6..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Branch Build Using Docker - -on: - push: - branches: - - feature/* - - hotfix/* - - release/* - - dev* - -env: - # solution path needs slashes (use \). When solution file name and path are put together, it should be a valid path - # If Solution is in repo root, leave SOLUTION_PATH empty - # solution name does not include extension. .sln is assumed - SOLUTION_PATH: PDT.LutronQuantum.EPI\ - SOLUTION_FILE: PDT.LutronQuantum.EPI - # Do not edit this, we're just creating it here - VERSION: 0.0.0-buildtype-buildnumber - # Defaults to debug for build type - BUILD_TYPE: Debug - # Defaults to master as the release branch. Change as necessary - RELEASE_BRANCH: master -jobs: - Build_Project: - runs-on: windows-latest - steps: - # First we checkout the source repo - - name: Checkout repo - uses: actions/checkout@v2 - with: - fetch-depth: 0 - submodules: true - token: ${{ secrets.PLUGIN_ACTION_TOKEN }} - # Fetch all tags - - name: Fetch tags - run: git fetch --tags - # Generate the appropriate version number - - name: Set Version Number - shell: powershell - run: | - $version = ./.github/scripts/GenerateVersionNumber.ps1 - Write-Output "::set-env name=VERSION::$version" - # Use the version number to set the version of the assemblies - - name: Update AssemblyInfo.cs - shell: powershell - run: | - Write-Output ${{ env.VERSION }} - ./.github/scripts/UpdateAssemblyVersion.ps1 ${{ env.VERSION }} - - name: restore Nuget Packages - run: nuget install .\packages.config -OutputDirectory .\packages -ExcludeVersion - # Login to Docker - - name: Login to Docker - uses: azure/docker-login@v1 - with: - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - # Build the solutions in the docker image - - name: Build Solution - shell: powershell - run: | - Invoke-Expression "docker run --rm --mount type=bind,source=""$($Env:GITHUB_WORKSPACE)"",target=""c:/project"" pepperdash/sspbuilder c:\cihelpers\vsidebuild.exe -Solution ""c:\project\$($Env:SOLUTION_PATH)$($Env:SOLUTION_FILE).sln"" -BuildSolutionConfiguration $($ENV:BUILD_TYPE)" - # Zip up the output files as needed - - name: Zip Build Output - shell: powershell - run: ./.github/scripts/ZipBuildOutput.ps1 - # Upload output files - - name: Upload Build Output - uses: actions/upload-artifact@v1 - with: - name: Build - path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - # Create the release on the source repo - - name: Create Release - id: create_release - uses: actions/create-release@v1 - with: - tag_name: ${{ env.VERSION }} - release_name: ${{ env.VERSION }} - prerelease: ${{contains('debug', env.BUILD_TYPE)}} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Upload the build package to the release - - name: Upload Release Package - id: upload_release - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - asset_name: ${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - asset_content_type: application/zip - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/essentialsplugins-betabuilds.yml b/.github/workflows/essentialsplugins-betabuilds.yml new file mode 100644 index 0000000..ac25c0e --- /dev/null +++ b/.github/workflows/essentialsplugins-betabuilds.yml @@ -0,0 +1,274 @@ +name: Branch Build Using Docker + +on: + push: + branches: + - feature/* + - hotfix/* + - release/* + - dev* + +env: + # Do not edit this, we're just creating it here + VERSION: 0.0.0-buildtype-buildnumber + # Defaults to debug for build type + BUILD_TYPE: Debug + # Defaults to master as the release branch. Change as necessary + RELEASE_BRANCH: main +jobs: + Build_Project: + runs-on: windows-latest + steps: + # First we checkout the source repo + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + # Fetch all tags + - name: Fetch tags + run: git fetch --tags + # Generate the appropriate version number + - name: Set Version Number + shell: powershell + run: | + $latestVersions = $(git tag --merged origin/main) + $latestVersion = [version]"0.0.0" + Foreach ($version in $latestVersions) { + Write-Host $version + try { + if (([version]$version) -ge $latestVersion) { + $latestVersion = $version + Write-Host "Setting latest version to: $latestVersion" + } + } + catch { + Write-Host "Unable to convert $($version). Skipping" + continue; + } + } + + $newVersion = [version]$latestVersion + $phase = "" + $newVersionString = "" + switch -regex ($Env:GITHUB_REF) { + '^refs\/heads\/main*.' { + $newVersionString = "{0}.{1}.{2}" -f $newVersion.Major, $newVersion.Minor, $newVersion.Build + } + '^refs\/heads\/feature\/*.' { + $phase = 'alpha' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/release\/*.' { + $splitRef = $Env:GITHUB_REF -split "/" + $version = [version]($splitRef[-1] -replace "v", "") + $phase = 'rc' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $version.Major, $version.Minor, $version.Build, $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/dev*.' { + $phase = 'beta' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + '^refs\/heads\/hotfix\/*.' { + $phase = 'hotfix' + $newVersionString = "{0}.{1}.{2}-{3}-{4}" -f $newVersion.Major, $newVersion.Minor, ($newVersion.Build + 1), $phase, $Env:GITHUB_RUN_NUMBER + } + } + echo "VERSION=$newVersionString" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # Use the version number to set the version of the assemblies + - name: Update AssemblyInfo.cs + shell: powershell + run: | + function Update-SourceVersion { + Param ([string]$Version) + #$fullVersion = $Version + $baseVersion = [regex]::Match($Version, "(\d+.\d+.\d+).*").captures.groups[1].value + $NewAssemblyVersion = 'AssemblyVersion("‘ + $baseVersion + ‘.*")' + Write-Output "AssemblyVersion = $NewAssemblyVersion" + $NewAssemblyInformationalVersion = 'AssemblyInformationalVersion("' + $Version + '")' + Write-Output "AssemblyInformationalVersion = $NewAssemblyInformationalVersion" + + foreach ($o in $input) { + Write-output $o.FullName + $TmpFile = $o.FullName + ".tmp" + get-content $o.FullName | + ForEach-Object { + $_ -replace 'AssemblyVersion\(".*"\)', $NewAssemblyVersion } | + ForEach-Object { + $_ -replace 'AssemblyInformationalVersion\(".*"\)', $NewAssemblyInformationalVersion + } > $TmpFile + move-item $TmpFile $o.FullName -force + } + } + + function Update-AllAssemblyInfoFiles ( $Env:VERSION ) { + foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" ) { + get-childitem -Path $Env:GITHUB_WORKSPACE -recurse | Where-Object { $_.Name -eq $file } | Update-SourceVersion $version ; + } + } + + # validate arguments + $r = [System.Text.RegularExpressions.Regex]::Match($args[0], "\d+\.\d+\.\d+.*"); + if ($r.Success) { + Write-Output "Updating Assembly Version to $args ..."; + Update-AllAssemblyInfoFiles $args[0]; + } + else { + Write-Output " "; + Write-Output "Error: Input version does not match x.y.z format!" + Write-Output " "; + Write-Output "Unable to apply version to AssemblyInfo.cs files"; + } + - name: restore Nuget Packages + run: nuget install .\packages.config -OutputDirectory .\packages -ExcludeVersion + # Set the SOLUTION_PATH + - name: Get SLN Path + shell: powershell + run: | + $solution_path = Get-ChildItem *.sln -recurse + $solution_path = $solution_path.FullName + $solution_path = $solution_path -replace "(?:[^\\]*\\){4}", "" + Write-Output $solution_path + echo "SOLUTION_PATH=$($solution_path)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # Set the SOLUTION_FILE + - name: Get SLN File + shell: powershell + run: | + $solution_file = Get-ChildItem .\*.sln -recurse -Path "$($Env:GITHUB_WORKSPACE)" + echo "SOLUTION_FILE=$($solution_file.BaseName)"| Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # Login to Docker + - name: Login to Docker + uses: azure/docker-login@v1 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + # Build the solutions in the docker image + - name: Build Solution + shell: powershell + run: | + Invoke-Expression "docker run --rm --mount type=bind,source=""$($Env:GITHUB_WORKSPACE)"",target=""c:/project"" pepperdash/sspbuilder c:\cihelpers\vsidebuild.exe -Solution ""c:\project\$($Env:SOLUTION_PATH)"" -BuildSolutionConfiguration $($ENV:BUILD_TYPE)" + # Zip up the output files as needed + - name: Zip Build Output + shell: powershell + run: | + $destination = "$($Env:GITHUB_HOME)\output" + New-Item -ItemType Directory -Force -Path ($destination) + Get-ChildItem ($destination) + $exclusions = "packages" + # Trying to get any .json schema files (not currently working) + # Gets any files with the listed extensions. + Get-ChildItem -recurse -Path "$($Env:GITHUB_WORKSPACE)" -include "*.clz", "*.cpz", "*.cplz", "*.nuspec" | ForEach-Object { + $allowed = $true; + # Exclude any files in submodules + foreach ($exclude in $exclusions) { + if ((Split-Path $_.FullName -Parent).contains("$($exclude)")) { + $allowed = $false; + break; + } + } + if ($allowed) { + Write-Host "allowing $($_)" + $_; + } + } | Copy-Item -Destination ($destination) -Force + Write-Host "Getting matching files..." + # Get any files from the output folder that match the following extensions + Get-ChildItem -Path $destination | Where-Object {($_.Extension -eq ".clz") -or ($_.Extension -eq ".cpz" -or ($_.Extension -eq ".cplz"))} | ForEach-Object { + # Replace the extensions with dll and xml and create an array + $filenames = @($($_ -replace "cpz|clz|cplz", "dll"), $($_ -replace "cpz|clz|cplz", "xml")) + Write-Host "Filenames:" + Write-Host $filenames + if ($filenames.length -gt 0) { + # Attempt to get the files and return them to the output directory + Get-ChildItem -Recurse -Path "$($Env:GITHUB_WORKSPACE)" -include $filenames | Copy-Item -Destination ($destination) -Force + } + } + Get-ChildItem -Path $destination\*.cplz | Rename-Item -NewName { "$($_.BaseName)-$($Env:VERSION)$($_.Extension)" } + Compress-Archive -Path $destination -DestinationPath "$($Env:GITHUB_WORKSPACE)\$($Env:SOLUTION_FILE)-$($Env:VERSION).zip" -Force + Write-Host "Output Contents post Zip" + Get-ChildItem -Path $destination + # Write the version to a file to be consumed by the push jobs + - name: Write Version + run: Write-Output "$($Env:VERSION)" | Out-File -FilePath "$($Env:GITHUB_HOME)\output\version.txt" + # Upload output files + - name: Upload Build Output + uses: actions/upload-artifact@v1 + with: + name: Build + path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip + # Upload the Version file as an artifact + - name: Upload version.txt + uses: actions/upload-artifact@v1 + with: + name: Version + path: ${{env.GITHUB_HOME}}\output\version.txt + # Create the release on the source repo + - name: Create Release + id: create_release + uses: fleskesvor/create-release@feature/support-target-commitish + with: + tag_name: ${{ env.VERSION }} + release_name: ${{ env.VERSION }} + prerelease: ${{contains('debug', env.BUILD_TYPE)}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Upload the build package to the release + - name: Upload Release Package + id: upload_release + uses: actions/upload-release-asset@v1 + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip + asset_name: ${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip + asset_content_type: application/zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + Push_Nuget_Package: + needs: Build_Project + runs-on: windows-latest + steps: + - name: Download Build Version Info + uses: actions/download-artifact@v1 + with: + name: Version + - name: Set Version Number + shell: powershell + run: | + Get-ChildItem "./Version" + $version = Get-Content -Path ./Version/version.txt + Write-Host "Version: $version" + echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Remove-Item -Path ./Version/version.txt + Remove-Item -Path ./Version + - name: Download Build output + uses: actions/download-artifact@v1 + with: + name: Build + path: ./ + - name: Unzip Build file + run: | + Get-ChildItem .\*.zip | Expand-Archive -DestinationPath .\ + Remove-Item -Path .\*.zip + - name: Copy Files to root & delete output directory + run: | + Remove-Item -Path .\* -Include @("*.cpz","*.md","*.cplz","*.json","*.dll","*.clz") + Get-ChildItem -Path .\output\* | Copy-Item -Destination .\ + Remove-Item -Path .\output -Recurse + - name: Get nuget File + shell: powershell + run: | + $nuspec_file = Get-ChildItem *.nuspec -recurse + echo "NUSPEC_FILE=$($nuspec_file.BaseName)"| Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Add nuget.exe + uses: nuget/setup-nuget@v1 + - name: Add Github Packages source + run: nuget sources add -name github -source https://nuget.pkg.github.com/pepperdash/index.json -username Pepperdash -password ${{ secrets.GITHUB_TOKEN }} + # Pushes to nuget, not needed unless publishing publicly + #- name: Add nuget.org API Key + # run: nuget setApiKey ${{ secrets.NUGET_API_KEY }} + - name: Create nuget package + run: nuget pack "./${{ env.NUSPEC_FILE}}.nuspec" -version ${{ env.VERSION }} + - name: Publish nuget package to Github registry + run: nuget push **/*.nupkg -source github + # Pushes to nuget, not needed unless publishing publicly >> this pushes package to nuget.org + #- name: Publish nuget package to nuget.org + # run: nuget push **/*.nupkg -Source https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 9a14647..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Master Build using Docker - -on: - release: - types: - - created - branches: - - master -env: - # solution path doesn't need slashes unless there it is multiple folders deep - # solution name does not include extension. .sln is assumed - SOLUTION_PATH: PDT.LutronQuantum.EPI\ - SOLUTION_FILE: PDT.LutronQuantum.EPI - # Do not edit this, we're just creating it here - VERSION: 0.0.0-buildtype-buildnumber - # Defaults to debug for build type - BUILD_TYPE: Release - # Defaults to master as the release branch. Change as necessary - RELEASE_BRANCH: master -jobs: - Build_Project: - runs-on: windows-latest - steps: - # First we checkout the source repo - - name: Checkout repo - uses: actions/checkout@v2 - with: - fetch-depth: 0 - submodules: true - token: ${{ secrets.PLUGIN_ACTION_TOKEN }} - # Generate the appropriate version number - - name: Set Version Number - shell: powershell - env: - TAG_NAME: ${{ github.event.release.tag_name }} - run: Write-Output "::set-env name=VERSION::$($Env:TAG_NAME)" - # Use the version number to set the version of the assemblies - - name: Update AssemblyInfo.cs - shell: powershell - run: | - Write-Output ${{ env.VERSION }} - ./.github/scripts/UpdateAssemblyVersion.ps1 ${{ env.VERSION }} - - name: restore Nuget Packages - run: nuget install .\packages.config -OutputDirectory .\packages -ExcludeVersion - # Login to Docker - - name: Login to Docker - uses: azure/docker-login@v1 - with: - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - # Build the solutions in the docker image - - name: Build Solution - shell: powershell - run: | - Invoke-Expression "docker run --rm --mount type=bind,source=""$($Env:GITHUB_WORKSPACE)"",target=""c:/project"" pepperdash/sspbuilder c:\cihelpers\vsidebuild.exe -Solution ""c:\project\$($Env:SOLUTION_PATH)\$($Env:SOLUTION_FILE).sln"" -BuildSolutionConfiguration $($ENV:BUILD_TYPE)" - # Zip up the output files as needed - - name: Zip Build Output - shell: powershell - run: ./.github/scripts/ZipBuildOutput.ps1 - - name: Upload Build Output - uses: actions/upload-artifact@v1 - with: - name: Build - path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - # Upload the build package to the release - - name: Upload Release Package - id: upload_release - uses: actions/upload-release-asset@v1 - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - asset_name: ${{ env.SOLUTION_FILE}}-${{ env.VERSION}}.zip - asset_content_type: application/zip - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 6214812..a00ee3a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ mono_crash.* [Dd]ebug/ [Dd]ebugPublic/ [Rr]eleases/ +[Rr]elease/ x64/ x86/ [Aa][Rr][Mm]/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index c9cc7fd..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ - -[submodule "EssentialsBuilds"] - path = EssentialsBuilds - url = https://github.com/PepperDash-Engineering/essentials-builds.git diff --git a/EssentialsBuilds b/EssentialsBuilds deleted file mode 160000 index 39b4d07..0000000 --- a/EssentialsBuilds +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 39b4d07afdd86136600e5cc0c30c00a1e5400c6e diff --git a/GetPackages.BAT b/GetPackages.BAT new file mode 100644 index 0000000..df9ca75 --- /dev/null +++ b/GetPackages.BAT @@ -0,0 +1,3 @@ +@Echo ON +nuget install .\packages.config -OutputDirectory .\Packages\ -excludeVersion +PAUSE \ No newline at end of file diff --git a/PDT.LutronQuantum.EPI/BoolWithFeedback.cs b/PDT.LutronQuantum.EPI/BoolWithFeedback.cs new file mode 100644 index 0000000..1133cb8 --- /dev/null +++ b/PDT.LutronQuantum.EPI/BoolWithFeedback.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Essentials.Core; +using PepperDash.Core; + +namespace LutronQuantum +{ + public class BoolWithFeedback + { + public BoolFeedback Feedback; + private bool _Value; + public bool Value + { + get + { + return _Value; + } + set + { + _Value = value; + Feedback.FireUpdate(); + + } + } + public BoolWithFeedback() + { + + Feedback = new BoolFeedback(() => { + return Value; + }); + } + } +} \ No newline at end of file diff --git a/PDT.LutronQuantum.EPI/Lutron-Quantum.nuspec b/PDT.LutronQuantum.EPI/Lutron-Quantum.nuspec new file mode 100644 index 0000000..55d7f30 --- /dev/null +++ b/PDT.LutronQuantum.EPI/Lutron-Quantum.nuspec @@ -0,0 +1,21 @@ + + + + PepperDash.Essentials.Plugin.LutronQuantum + 2.0.2 + Lutron Quantum Essentials Plugin + PepperDash Technologies + pepperdash + false + MIT + https://github.com/PepperDash-Engineering/epi-lighting-lutron_quantum + Copyright 2021 + This software is a plugin designed to work as a part of PepperDash Essentials for Crestron control processors. + crestron 3series 4series lutron quantum + + + + + + + \ No newline at end of file diff --git a/PDT.LutronQuantum.EPI/LutronQseIO.cs b/PDT.LutronQuantum.EPI/LutronQseIO.cs new file mode 100644 index 0000000..0e432d6 --- /dev/null +++ b/PDT.LutronQuantum.EPI/LutronQseIO.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using PepperDash.Essentials; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Lighting; +using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Core.Devices; +using PepperDash.Core; +using PepperDash.Essentials.Bridges; +using PepperDash.Essentials.Core; +using Crestron.SimplSharpPro.DeviceSupport; + + +namespace LutronQuantum +{ + public class LutronQseIO : Device, iLutronDevice, IBridge + { + private LutronQuantum LutronDevice; + LutronQseIOConfigObject _Properties; + public Dictionary Feedbacks = new Dictionary(); + + public static void LoadPlugin() + { + PepperDash.Essentials.Core.DeviceFactory.AddFactoryForType("LutronQseIO", LutronQseIO.BuildDevice); + } + + public static LutronQseIO BuildDevice(DeviceConfig dc) + { + var config = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + var newMe = new LutronQseIO(dc, config); + return newMe; + } + + public LutronQseIO(DeviceConfig config, LutronQseIOConfigObject props) + : base(config.Key, config.Name) + { + _Properties = props; + Feedbacks.Add("1", new BoolWithFeedback()); + Feedbacks.Add("2", new BoolWithFeedback()); + Feedbacks.Add("3", new BoolWithFeedback()); + Feedbacks.Add("4", new BoolWithFeedback()); + Feedbacks.Add("5", new BoolWithFeedback()); + + } + public override bool CustomActivate() + { + LutronDevice = DeviceManager.GetDeviceForKey(_Properties.LightingDeviceKey) as LutronQuantum; + if (LutronDevice == null) + { + Debug.Console(0, this, "LutronQuantum device {0} does not exist", _Properties.LightingDeviceKey); + } + else + { + LutronDevice.AddDevice(_Properties.IntegrationId, this); + + } + AddPostActivationAction(() => + { + Initialize(); + }); + + + return true; + } + public void Initialize() + { + LutronDevice.SendLine("#MONITORING,2,1"); + LutronDevice.SendLine(string.Format("~DEVICE,{0},1", _Properties.IntegrationId)); + LutronDevice.SendLine(string.Format("~DEVICE,{0},2", _Properties.IntegrationId)); + LutronDevice.SendLine(string.Format("~DEVICE,{0},3", _Properties.IntegrationId)); + LutronDevice.SendLine(string.Format("~DEVICE,{0},4", _Properties.IntegrationId)); + LutronDevice.SendLine(string.Format("~DEVICE,{0},5", _Properties.IntegrationId)); + } + public void ParseMessage(string[] message) + { + Debug.Console(2, "QseIO Got Message {0} {1} {2} {3} ", message[0],message[1],message[2], message[3]); + BoolWithFeedback fb; + if (Feedbacks.TryGetValue(message[2], out fb)) + { + if (message[3] == "3") + { + fb.Value = false; + } + if (message[3] == "4") + { + fb.Value = true; + } + } + } + + + #region IBridge Members + + public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey) + { + this.LinkToApiExt(trilist, joinStart, joinMapKey); + } + + #endregion + + + + } +} \ No newline at end of file diff --git a/PDT.LutronQuantum.EPI/LutronQseIOBridge.cs b/PDT.LutronQuantum.EPI/LutronQseIOBridge.cs new file mode 100644 index 0000000..e06bccf --- /dev/null +++ b/PDT.LutronQuantum.EPI/LutronQseIOBridge.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Crestron.SimplSharp; +using Crestron.SimplSharpPro.DeviceSupport; + +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Bridges; +using Newtonsoft.Json; + +namespace LutronQuantum +{ + public static class LutronQseIOBridge + { + + public static void LinkToApiExt(this LutronQseIO device, BasicTriList trilist, uint joinStart, string joinMapKey) + { + LutronQseIOJoinMap joinMap = new LutronQseIOJoinMap(); + joinMap.OffsetJoinNumbers(joinStart); + var x = 0; + foreach (var cc in device.Feedbacks) + { + + Debug.Console(2, "Linking {0} {1}", cc.Key, joinMap.ContactClosureStart + x); + cc.Value.Feedback.LinkInputSig(trilist.BooleanInput[(uint)(joinMap.ContactClosureStart + x)]); + x++; + } + + } + + public class LutronQseIOJoinMap : JoinMapBase + { + public uint ContactClosureStart { get; set; } + + public LutronQseIOJoinMap() + { + // Digital + ContactClosureStart = 1; + + + // Analog + + // Serial + + } + + public override void OffsetJoinNumbers(uint joinStart) + { + var joinOffset = joinStart - 1; + ContactClosureStart = ContactClosureStart + joinOffset; + } + } + } +} \ No newline at end of file diff --git a/PDT.LutronQuantum.EPI/LutronQseIOConfigObject.cs b/PDT.LutronQuantum.EPI/LutronQseIOConfigObject.cs new file mode 100644 index 0000000..afe4ce0 --- /dev/null +++ b/PDT.LutronQuantum.EPI/LutronQseIOConfigObject.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Config; +using PepperDash.Essentials.Core.Lighting; + +namespace LutronQuantum +{ + public class LutronQseIOConfigObject + { + public string IntegrationId { get; set; } + public string LightingDeviceKey { get; set; } + + } +} \ No newline at end of file diff --git a/PDT.LutronQuantum.EPI/LutronQuantum.cs b/PDT.LutronQuantum.EPI/LutronQuantum.cs index 41995e6..ff7d718 100644 --- a/PDT.LutronQuantum.EPI/LutronQuantum.cs +++ b/PDT.LutronQuantum.EPI/LutronQuantum.cs @@ -43,6 +43,7 @@ public static LutronQuantum BuildDevice(DeviceConfig dc) public IBasicCommunication Communication { get; private set; } public CommunicationGather PortGather { get; private set; } public StatusMonitorBase CommunicationMonitor { get; private set; } + public bool Is232; CTimer SubscribeAfterLogin; @@ -52,6 +53,8 @@ public static LutronQuantum BuildDevice(DeviceConfig dc) string Username; string Password; + public Dictionary LutronDevices = new Dictionary(); + const string Delimiter = "\x0d\x0a"; const string Set = "#"; const string Get = "?"; @@ -72,6 +75,10 @@ public LutronQuantum(DeviceConfig config, IBasicCommunication comm, LutronQuantu Username = props.Control.TcpSshProperties.Username; Password = props.Control.TcpSshProperties.Password; } + else + { + Is232 = true; + } LightingScenes = props.Scenes; @@ -106,7 +113,10 @@ public override bool CustomActivate() Communication.Connect(); CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); }; CommunicationMonitor.Start(); - + if (Is232) + { + SubscribeToFeedback(); + } return true; } @@ -117,6 +127,7 @@ void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) if (e.Client.IsConnected) { // Tasks on connect + } } @@ -127,7 +138,7 @@ void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) /// void Communication_TextReceived(object sender, GenericCommMethodReceiveTextArgs args) { - Debug.Console(2, this, "Text Received: '{0}'", args.Text); + //Debug.Console(2, this, "Text Received: '{0}'", args.Text); if (args.Text.Contains("login:")) { @@ -162,37 +173,48 @@ void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs arg try { - if (args.Text.Contains("~AREA")) - { - var response = args.Text.Split(','); - - var integrationId = response[1]; - - if (integrationId != IntegrationId) - { - Debug.Console(2, this, "Response is not for correct Integration ID"); - return; - } - else - { - var action = Int32.Parse(response[2]); - - switch (action) - { - case (int)eAction.Scene: - { - var scene = response[3]; - CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID.Equals(scene)); - - OnLightingSceneChange(); - - break; - } - default: - break; - } - } - } + if (args.Text.Contains(',')) + { + var response = args.Text.Split(','); + var command = response[0]; + var integrationId = response[1]; + if (command.Contains("~AREA")) + { + if (integrationId != IntegrationId) + { + Debug.Console(2, this, "Response is not for correct Integration ID"); + return; + } + else + { + var action = Int32.Parse(response[2]); + + switch (action) + { + case (int)eAction.Scene: + { + var scene = response[3]; + CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID.Equals(scene)); + + OnLightingSceneChange(); + + break; + } + default: + break; + } + } + } + else if (command.Contains("~DEVICE")) + { + iLutronDevice device; + + if (LutronDevices.TryGetValue(integrationId, out device)) + { + device.ParseMessage(response); + } + } + } } catch (Exception e) { @@ -206,9 +228,14 @@ void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs arg public void SubscribeToFeedback() { Debug.Console(1, "Sending Monitoring Subscriptions"); + SendLine("#MONITORING,6,1"); SendLine("#MONITORING,8,1"); SendLine("#MONITORING,5,2"); + foreach (var device in LutronDevices.Values) + { + device.Initialize(); + } } /// @@ -324,6 +351,11 @@ public void SendLine(string s) Debug.Console(2, this, "TX: '{0}'", s); Communication.SendText(s + Delimiter); } + + public void AddDevice(string integrationID, iLutronDevice device) + { + LutronDevices.Add(integrationID, device); + } #region IBridge Members public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey) diff --git a/PDT.LutronQuantum.EPI/LutronQuantumBridge.cs b/PDT.LutronQuantum.EPI/LutronQuantumBridge.cs index a80d369..2980737 100644 --- a/PDT.LutronQuantum.EPI/LutronQuantumBridge.cs +++ b/PDT.LutronQuantum.EPI/LutronQuantumBridge.cs @@ -33,7 +33,35 @@ public static void LinkToApiExt(this LutronQuantum lightingDevice, BasicTriList trilist.SetStringSigAction(joinMap.ShadeGroup2IdSet, id => lightingDevice.SetShadeGroup2Id(id)); // GenericLighitng Actions & FeedBack - trilist.SetUShortSigAction(joinMap.SelectScene, u => lightingDevice.SelectScene(lightingDevice.LightingScenes[u])); + trilist.SetUShortSigAction(joinMap.SelectScene, u => + { + if(u <= lightingDevice.LightingScenes.Count) + { + lightingDevice.SelectScene(lightingDevice.LightingScenes[u]); + } + }); + trilist.SetBoolSigAction(joinMap.Raise, b => + { + if (b) + { + lightingDevice.MasterRaise(); + } + else + { + lightingDevice.MasterRaiseLowerStop(); + } + }); + trilist.SetBoolSigAction(joinMap.Lower, b => + { + if (b) + { + lightingDevice.MasterLower(); + } + else + { + lightingDevice.MasterRaiseLowerStop(); + } + }); int sceneIndex = 1; foreach (var scene in lightingDevice.LightingScenes) { @@ -75,6 +103,8 @@ public static void LinkToApiExt(this LutronQuantum lightingDevice, BasicTriList public class LutronQuantumJoinMap : JoinMapBase { public uint IsOnline { get; set; } + public uint Raise { get; set; } + public uint Lower { get; set; } public uint SelectScene { get; set; } public uint LightingSceneOffset { get; set; } public uint ButtonVisibilityOffset { get; set; } @@ -93,6 +123,8 @@ public LutronQuantumJoinMap() SelectScene = 1; LightingSceneOffset = 10; ButtonVisibilityOffset = 40; + Raise = 2; + Lower = 3; ShadeGroup1Raise = 60; ShadeGroup1Lower = 61; ShadeGroup2Raise = 62; @@ -110,6 +142,8 @@ public override void OffsetJoinNumbers(uint joinStart) { var joinOffset = joinStart - 1; IsOnline = IsOnline + joinOffset; + Raise = Raise + joinOffset; + Lower = Lower + joinOffset; SelectScene = SelectScene + joinOffset; LightingSceneOffset = LightingSceneOffset + joinOffset; ButtonVisibilityOffset = ButtonVisibilityOffset + joinOffset; diff --git a/PDT.LutronQuantum.EPI/Lutron_NWK_API.pdf b/PDT.LutronQuantum.EPI/Lutron_NWK_API.pdf new file mode 100644 index 0000000..f547bff Binary files /dev/null and b/PDT.LutronQuantum.EPI/Lutron_NWK_API.pdf differ diff --git a/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.csproj b/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.csproj index 0c43495..3d07f67 100644 --- a/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.csproj +++ b/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.csproj @@ -46,26 +46,26 @@ off - + False - ..\EssentialsBuilds\Essentials Devices Common.dll + ..\Packages\PepperDashEssentials\lib\net35\Essentials Devices Common.dll - + False - ..\EssentialsBuilds\PepperDashEssentials.dll + ..\Packages\PepperDashEssentials\lib\net35\PepperDashEssentials.dll - + False - ..\EssentialsBuilds\PepperDash_Core.dll + ..\Packages\PepperDashEssentials\lib\net35\PepperDash_Core.dll - + False - ..\EssentialsBuilds\PepperDash_Essentials_Core.dll + ..\Packages\PepperDashEssentials\lib\net35\PepperDash_Essentials_Core.dll - + False - ..\EssentialsBuilds\PepperDash_Essentials_DM.dll + ..\Packages\PepperDashEssentials\lib\net35\PepperDash_Essentials_DM.dll False @@ -95,6 +95,11 @@ + + + + + diff --git a/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.suo b/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.suo index a430cb6..dd85d1c 100644 Binary files a/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.suo and b/PDT.LutronQuantum.EPI/PDT.LutronQuantum.EPI.suo differ diff --git a/PDT.LutronQuantum.EPI/iLutronDevice.cs b/PDT.LutronQuantum.EPI/iLutronDevice.cs new file mode 100644 index 0000000..80dd1a0 --- /dev/null +++ b/PDT.LutronQuantum.EPI/iLutronDevice.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +namespace LutronQuantum +{ + public interface iLutronDevice + { + void Initialize(); + void ParseMessage(string[] message); + } +} \ No newline at end of file diff --git a/packages.config b/packages.config index 6c509dd..972b2f0 100644 --- a/packages.config +++ b/packages.config @@ -1,3 +1,3 @@ - + \ No newline at end of file