Implémentation CLI PowerShell Enocean Eclypse
This commit is contained in:
74
modules/XmlParser.psm1
Normal file
74
modules/XmlParser.psm1
Normal file
@@ -0,0 +1,74 @@
|
||||
# Module XmlParser - Parse et generation XML Enocean
|
||||
|
||||
function Get-DeviceListFromJson {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$JsonContent
|
||||
)
|
||||
|
||||
$json = $JsonContent | ConvertFrom-Json
|
||||
|
||||
$devices = @()
|
||||
if ($json.files) {
|
||||
foreach ($file in $json.files) {
|
||||
$devices += @{
|
||||
Name = $file.path.name
|
||||
Href = $file.path.href
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return , $devices
|
||||
}
|
||||
|
||||
function Parse-EnoceanDeviceXml {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$XmlContent
|
||||
)
|
||||
|
||||
[xml]$xml = $XmlContent
|
||||
$config = $xml.EnOceanDevice.Configuration
|
||||
|
||||
return @{
|
||||
ResourceNumber = [int]$config.ResourceNumber
|
||||
DeviceId = $config.DeviceId
|
||||
DeviceType = $config.DeviceType
|
||||
}
|
||||
}
|
||||
|
||||
function New-EnoceanDeviceXml {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[int]$ResourceNumber,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$DeviceId,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$DeviceType
|
||||
)
|
||||
|
||||
$xml = @"
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<EnOceanDevice>
|
||||
<Configuration>
|
||||
<ResourceType>EnOceanDevice</ResourceType>
|
||||
<ResourceNumber>$ResourceNumber</ResourceNumber>
|
||||
<Name>EnOcean Device $ResourceNumber</Name>
|
||||
<DeviceId>$DeviceId</DeviceId>
|
||||
<DeviceType>$DeviceType</DeviceType>
|
||||
<MaxReceiveTime>2400</MaxReceiveTime>
|
||||
<Points></Points>
|
||||
<Description></Description>
|
||||
</Configuration>
|
||||
</EnOceanDevice>
|
||||
"@
|
||||
|
||||
return $xml
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Get-DeviceListFromJson, Parse-EnoceanDeviceXml, New-EnoceanDeviceXml
|
||||
Reference in New Issue
Block a user