Updated HA package
Refresh-HADeviceRegistry added prompts as well as generalization using the profile.d set variables. Added profile.d template file for smoother setup Added HA Addon commands
This commit is contained in:
parent
b410ec839d
commit
2aa29de253
8 changed files with 146 additions and 26 deletions
|
@ -1,47 +1,69 @@
|
|||
Push-Location /srv/ha/current/homeassistant/.storage
|
||||
[CmdletBinding()]param([switch]$ApplyChanges)
|
||||
Push-Location (Join-Path $(Get-HAPath) '.storage')
|
||||
|
||||
$Count = [ordered]@{
|
||||
Devices=[PSCustomObject]([ordered]@{
|
||||
Before = -1
|
||||
After = -1
|
||||
Removed = -1
|
||||
BeforeData = $null
|
||||
AfterData = $null
|
||||
})
|
||||
Entities=[PSCustomObject]([ordered]@{
|
||||
Before = -1
|
||||
After = -1
|
||||
Removed = -1
|
||||
BeforeData = $null
|
||||
AfterData = $null
|
||||
})
|
||||
}
|
||||
$devices = $(Get-Content ./core.device_registry | ConvertFrom-Json -Depth 10)
|
||||
$Count.Devices.Before = $devices.data.devices.count
|
||||
$devices.data.devices = $devices.data.devices |
|
||||
# Where-Object identifiers -notmatch 'zwave'
|
||||
Where-Object {$_.identifiers[0] -eq 'zha'}
|
||||
|
||||
$entities = $(Get-Content ./core.entity_registry | ConvertFrom-Json -Depth 10)
|
||||
$Count.Entities.BeforeData = $entities.data.entities
|
||||
$Count.Entities.Before = $entities.data.entities.count
|
||||
$entities.data.entities = $entities.data.entities |
|
||||
Where-Object platform -match 'zha'
|
||||
# Where-Object platform -notmatch zwave |
|
||||
# Where-Object { -not (
|
||||
# $_.platform -match 'switch' -and $_.entity_id -match 'light\.' -and -not $_.config_entry_id
|
||||
# ) }
|
||||
Where-Object {
|
||||
( $_.platform -match 'zha' ) -or ($_.Original_name -in $HAPreserveEntities)
|
||||
}
|
||||
$Count.Entities.AfterData = $entities.data.entities
|
||||
|
||||
$devices = $(Get-Content ./core.device_registry | ConvertFrom-Json -Depth 10)
|
||||
$Count.Devices.BeforeData = $devices.data.devices
|
||||
$Count.Devices.Before = $devices.data.devices.count
|
||||
$devices.data.devices = $devices.data.devices |
|
||||
Where-Object id -in $($entities.data.entities.device_id)
|
||||
# Where-Object identifiers -notmatch 'zwave'
|
||||
# Where-Object {$_.identifiers[0] -in 'zha','smartthings' }
|
||||
$Count.Devices.AfterData = $devices.data.devices
|
||||
|
||||
$Count.Devices.After = $devices.data.devices.count
|
||||
$Count.Entities.After = $entities.data.entities.count
|
||||
$Count.Devices.Removed = $Count.Devices.Before - $Count.Devices.After
|
||||
$Count.Entities.Removed = $Count.Entities.Before - $Count.Entities.After
|
||||
|
||||
$Count | Format-Table
|
||||
$Count
|
||||
|
||||
$devices | ConvertTo-Json -Depth 10 > /tmp/new.core.device_registry
|
||||
$entities | ConvertTo-Json -Depth 10 > /tmp/new.core.entity_registry
|
||||
|
||||
ha core stop
|
||||
sudo mv ./core.entity_registry ./core.entity_registry.old
|
||||
sudo mv ./core.device_registry ./core.device_registry.old
|
||||
sudo cp /tmp/new.core.entity_registry ./core.entity_registry
|
||||
sudo cp /tmp/new.core.device_registry ./core.device_registry
|
||||
if( $ApplyChanges ) {
|
||||
Write-Host -ForegroundColor Cyan $(
|
||||
"Stopping Home-Assistant Core, if a timeout occurs, you might need"+
|
||||
"`nto the following command to start the core manually:"+
|
||||
"`n ha core start"
|
||||
)
|
||||
ha core stop
|
||||
$local:_ts = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
sudo mv ./core.entity_registry ./core.entity_registry.$_ts.old
|
||||
sudo mv ./core.device_registry ./core.device_registry.$_ts.old
|
||||
sudo cp /tmp/new.core.entity_registry ./core.entity_registry
|
||||
sudo cp /tmp/new.core.device_registry ./core.device_registry
|
||||
}
|
||||
Pop-Location
|
||||
|
||||
|
||||
ha core start
|
||||
if( $ApplyChanges ) {
|
||||
Write-Host -ForegroundColor Cyan $(
|
||||
"Starting Home-Assistant Core, if a timeout occurs, wait a bit, and check your gui"
|
||||
)
|
||||
ha core start
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue