- CLI PowerShell pour la gestion des sorties DALI adressable (ECxLightDaliA) - Action Read : rapport CSV des configurations (une ligne par output) - Action Write : modification des propriétés via POST JSON - Fallback curl.exe -k pour les automates avec problèmes SSL
125 lines
3.5 KiB
PowerShell
125 lines
3.5 KiB
PowerShell
# Module DaliParser - Parsing JSON modules DALI et construction body Write
|
|
|
|
function Get-DaliAModules {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$JsonContent
|
|
)
|
|
|
|
$data = $JsonContent | ConvertFrom-Json
|
|
$results = @()
|
|
|
|
foreach ($prop in $data.PSObject.Properties) {
|
|
$moduleKey = $prop.Name
|
|
$module = $prop.Value
|
|
|
|
# Filtrer uniquement les modules ECxLightDaliA
|
|
if ($module."configured-module-type" -ne "ECxLightDaliA") {
|
|
continue
|
|
}
|
|
|
|
$moduleName = $module.name
|
|
|
|
foreach ($outProp in $module.outputs.PSObject.Properties) {
|
|
$outputKey = $outProp.Name
|
|
$output = $outProp.Value
|
|
|
|
$results += [PSCustomObject][ordered]@{
|
|
ModuleKey = $moduleKey
|
|
ModuleName = $moduleName
|
|
OutputKey = $outputKey
|
|
OutputName = $output.name
|
|
ControlGearKey = $output."control-gear-key"
|
|
Groups = (ConvertTo-GroupString -GroupArray $output."group-membership")
|
|
SystemFailLevel = $output."system-fail-level"
|
|
PowerOnLevel = $output."power-on-level"
|
|
MinDimmingLevel = $output."minimum-dimming-level"
|
|
DefaultValue = $output."default-value"
|
|
DimmingTime = $output."dimming-time"
|
|
MaxDimmingLevel = $output."maximum-dimming-level"
|
|
}
|
|
}
|
|
}
|
|
|
|
return $results
|
|
}
|
|
|
|
function ConvertTo-GroupString {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
$GroupArray
|
|
)
|
|
|
|
$activeGroups = @()
|
|
for ($i = 0; $i -lt $GroupArray.Count; $i++) {
|
|
if ($GroupArray[$i] -eq $true) {
|
|
$activeGroups += ($i + 1)
|
|
}
|
|
}
|
|
|
|
return ($activeGroups -join ",")
|
|
}
|
|
|
|
function ConvertFrom-GroupString {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[AllowEmptyString()]
|
|
[string]$GroupString
|
|
)
|
|
|
|
$arr = @($false) * 16
|
|
|
|
if ($GroupString -and $GroupString.Trim() -ne "") {
|
|
$indices = $GroupString.Split(",") | ForEach-Object { [int]$_.Trim() }
|
|
foreach ($idx in $indices) {
|
|
if ($idx -ge 1 -and $idx -le 16) {
|
|
$arr[$idx - 1] = $true
|
|
}
|
|
}
|
|
}
|
|
|
|
return , $arr
|
|
}
|
|
|
|
function Build-ModuleWriteBody {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$ModuleKey,
|
|
|
|
[Parameter(Mandatory)]
|
|
[array]$OutputRows
|
|
)
|
|
|
|
$outputs = @{}
|
|
|
|
foreach ($row in $OutputRows) {
|
|
$outputKey = $row.OutputKey
|
|
$groupArray = ConvertFrom-GroupString -GroupString $row.Groups
|
|
|
|
$outputs[$outputKey] = [ordered]@{
|
|
"control-gear-key" = [string]$row.ControlGearKey
|
|
"group-membership" = $groupArray
|
|
"system-fail-level" = [double]$row.SystemFailLevel
|
|
"power-on-level" = [double]$row.PowerOnLevel
|
|
"minimum-dimming-level" = [double]$row.MinDimmingLevel
|
|
"default-value" = [double]$row.DefaultValue
|
|
"dimming-time" = [double]$row.DimmingTime
|
|
"maximum-dimming-level" = [double]$row.MaxDimmingLevel
|
|
}
|
|
}
|
|
|
|
$body = @{
|
|
$ModuleKey = @{
|
|
"outputs" = $outputs
|
|
}
|
|
}
|
|
|
|
return ($body | ConvertTo-Json -Depth 10)
|
|
}
|
|
|
|
Export-ModuleMember -Function Get-DaliAModules, ConvertTo-GroupString, ConvertFrom-GroupString, Build-ModuleWriteBody
|