public/Disable-Yeelight.ps1
<#
.SYNOPSIS Turns off Yeelight Lightstrip .DESCRIPTION The function turns off Yeelight Lightstrip. .EXAMPLE PS C:\> Disable-Yeelight -Name Office .EXAMPLE PS C:\> Disable-Yeelight -Name Office -PassThru .NOTES Author: Mateusz Nadobnik Link: akademiapowershell.pl Date: 14-11-2020 Version: 0.0.1 Keywords: enable, turn on, yeelight, xiaomi Notes: Changelog: #> function Disable-Yeelight { [cmdletbinding()] param( [Parameter(Mandatory, ParameterSetName = 'Name', Position = 0)] [string]$Name, [switch]$PassThru ) try { if ($null -ne $Name) { $Device = $script:connections | Where-Object Name -eq $Name } if ($null -ne $Device) { $Device.Turnoff().Wait() if ($PassThru.IsPresent) { [PSCustomObject]@{ Name = $Device.Name Hostname = $Device.Hostname IsConnected = $Device.IsConnected Power = $Device.Properties['power'] } } } else { Write-Warning 'The connection not exist. Use Connect-Yeelight function and try again.' } } catch { Write-Warning $_ } } |