operations.ps1

function Invoke-MetasysReadAttribute {
    <#
    .SYNOPSIS
        Read the specified attribute of the specified object

    .DESCRIPTION
        This function calls the get attribute value operation using the object id and
        attribute id specified.

    .OUTPUTS
        System.String
            The payloads from Metasys are formatted JSON strings. This is the default return type for this function.

    .EXAMPLE
        Invoke-MetasysReadAttribute -ObjectId ba1a703a-1e96-54ae-9ae6-9590a55c2e4a -AttributeId name

        This will read the attribute `name` of the object and return its value.

        MOLEX LIGHT POWER

    #>

    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [String]$ObjectId,

        [Parameter(Mandatory = $true, Position = 1)]
        [String]$AttributeId
    )

    $response = Invoke-MetasysMethod "/objects/$ObjectId/attributes/$AttributeId" -ReturnBodyAsObject

    $response.item[$AttributeId]

    if (([System.Management.Automation.OrderedHashtable]$response.condition).ContainsKey($AttributeId)) {

        Write-Warning ("$AttributeId has non-normal conditions $(ConvertTo-Json $response.condition[$AttributeId])")

    }
}


Set-Alias -Name ira -Value Invoke-MetasysReadAttribute

Export-ModuleMember -Function 'Invoke-MetasysReadAttribute'
Export-ModuleMember -Alias 'ira'


# function Invoke-MetasysWriteAttribute {
# param(
# []
# )
# }