Skip to content

Commit

Permalink
Merge pull request #31 from MartijnvanGeffen13/Beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
MartijnvanGeffen13 authored Dec 2, 2024
2 parents 0a0dfbd + a43f712 commit 7286252
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 13 deletions.
101 changes: 101 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# Docker image file that describes an Ubuntu20.04 image with PowerShell installed from Microsoft APT Repo
ARG hostRegistry=psdockercache.azurecr.io
FROM ${hostRegistry}/ubuntu:24.04 AS installer-env

# Define Args for the needed to add the package
ARG PS_VERSION=7.5.0-preview.5
ARG PS_PACKAGE=powershell-preview_${PS_VERSION}-1.deb_amd64.deb
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE}
ARG PS_INSTALL_VERSION=7-preview

RUN --mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt-get update \
&& apt-get install --no-install-recommends -y \
# curl is required to grab the Linux package
curl \
# less is required for help in powershell
less \
# requied to setup the locale
locales \
# required for SSL
ca-certificates \
# Download the Linux package and save it
&& echo ${PS_PACKAGE_URL} \
&& curl -sSL ${PS_PACKAGE_URL} -o /tmp/powershell.deb

# Install the deb file in this image and make powershell available
ARG hostRegistry=psdockercache.azurecr.io
FROM ${hostRegistry}/ubuntu:24.04 AS final-image

# # Define args needed to add the package
ARG PS_VERSION=7.5.0-preview.5
ARG PS_PACKAGE=powershell-preview_${PS_VERSION}-1.deb_amd64.deb
ARG PS_PACKAGE_URL=https://github.com/PowerShell/PowerShell/releases/download/v${PS_VERSION}/${PS_PACKAGE}
ARG PS_INSTALL_VERSION=7-preview

# Define ENVs for Localization/Globalization
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
PS_INSTALL_FOLDER=/opt/microsoft/powershell/$PS_INSTALL_VERSION \
# set a fixed location for the Module analysis cache
PSModuleAnalysisCachePath=/var/cache/microsoft/powershell/PSModuleAnalysisCache/ModuleAnalysisCache \
POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-Ubuntu-24.04

# Install dependencies and clean up
RUN --mount=from=installer-env,target=/mnt/pwsh,source=/tmp \
--mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt-get update \
&& apt-get install --no-install-recommends -y /mnt/pwsh/powershell.deb \
&& apt-get install --no-install-recommends -y \
# less is required for help in powershell
less \
# requied to setup the locale
locales \
# required for SSL
ca-certificates \
gss-ntlmssp \
libicu74 \
libssl3 \
libc6 \
libgcc1 \
libgssapi-krb5-2 \
liblttng-ust1 \
libstdc++6 \
zlib1g \
# PowerShell remoting over SSH dependencies
openssh-client \
&& apt-get dist-upgrade -y \
&& locale-gen $LANG && update-locale \
&& export POWERSHELL_TELEMETRY_OPTOUT=1 \
# Give all user execute permissions and remove write permissions for others
&& chmod a+x,o-w ${PS_INSTALL_FOLDER}/pwsh \
# Create the pwsh symbolic link that points to powershell
&& ln -sf ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh \
# Create the pwsh-preview symbolic link that points to powershell
&& ln -sf ${PS_INSTALL_FOLDER}/pwsh /usr/bin/pwsh-preview \
&& pwsh \
-NoLogo \
-NoProfile \
-Command " \
\$ErrorActionPreference = 'Stop' ; \
\$ProgressPreference = 'SilentlyContinue' ; \
while(!(Test-Path -Path \$env:PSModuleAnalysisCachePath)) { \
Write-Host "'Waiting for $env:PSModuleAnalysisCachePath'" ; \
Start-Sleep -Seconds 6 ; \
}"

# Use PowerShell as the default shell
# Use array to avoid Docker prepending /bin/sh -c


WORKDIR /volvo4evcc

COPY / .

CMD [ "pwsh-preview" ]
2 changes: 1 addition & 1 deletion Volvo4evcc.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'Volvo4evcc.psm1'

# Version number of this module.
ModuleVersion = '1.5'
ModuleVersion = '1.8.1'

# ID used to uniquely identify this module
GUID = '50047ffd-8482-4a42-94f3-52bbf7515d93'
Expand Down
2 changes: 1 addition & 1 deletion Volvo4evcc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ foreach ($File in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -Filter *.ps

foreach ($File in (Get-ChildItem "$PSScriptRoot\internal" -Recurse -Filter *.ps1)) {
. $File.FullName
}
}

30 changes: 23 additions & 7 deletions functions/functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ Function Start-Volvo4Evcc
$Token = Confirm-VolvoAuthentication

#Wrap in loop based on evcc data
$Seconds = 60
$RunCount = 0
$Seconds = 15
[Int64]$RunCount = 0
do
{
#Clean itterative variables

#Increase run count
$RunCount++

Expand All @@ -166,33 +168,34 @@ Function Start-Volvo4Evcc

}
#Get EvccData
#If multiple loadpoints Array returns all loadpoints. Testing for true means if any is true it will run.
$EvccData = Get-EvccData
$MessageDone = $False

If ($True -eq $EvccData.SourceOk){
#Get Volvo data 2 times slower than every poll
If ($true -eq $EvccData.Connected -and $true -eq $EvccData.Charging -and ($RunCount%2) -eq 0){
If ($true -eq $EvccData.Connected -and $true -eq $EvccData.Charging -and ($RunCount%8) -eq 0){

Write-LogEntry -Severity 0 -Message 'Connected - charging - Fast refresh of volvo SOC data'
$MessageDone = $True
Watch-VolvoCar -Token $Token
}
#Get Volvo data 5 times slower than every poll
If ($true -eq $EvccData.Connected -and $false -eq $EvccData.Charging -and ($RunCount%5) -eq 0){
If ($true -eq $EvccData.Connected -and $false -eq $EvccData.Charging -and ($RunCount%20) -eq 0){
#Also cycle web service
Write-LogEntry -Severity 0 -Message 'Connected - Not charging - Slow refresh of volvo SOC data'
$MessageDone = $True
Watch-VolvoCar -Token $Token
}

#Get weather forecast and set MinSOC if needed
If ($true -eq $Global:Config.'Weather.Enabled' -and ($RunCount%60) -eq 0){
If ($true -eq $Global:Config.'Weather.Enabled' -and ($RunCount%240) -eq 0){
Update-SunHours
}


#Get Volvo data 5 times slower than every poll
If ($false -eq $EvccData.Connected -and ($RunCount%60) -eq 0){
If ($false -eq $EvccData.Connected -and ($RunCount%240) -eq 0){

Write-LogEntry -Severity 0 -Message 'Not Connected - Super Slow Refresh of volvo SOC data - once every hour'
$MessageDone = $True
Expand All @@ -210,6 +213,17 @@ Function Start-Volvo4Evcc
$MessageDone = $True
Watch-VolvoCar -Token $Token
}


$EmergencyUpdateCompare = Compare-Object -ReferenceObject $LastPulseEvccData -DifferenceObject $EvccData.Connected
If ($EmergencyUpdateCompare.SideIndicator -contains "=>" -or $EmergencyUpdateCompare -contains "<="){
#If there is a differance in connection state do a emergency update without waiting for pull
Write-LogEntry -Severity 0 -Message "Emergency Push due to connection dif was:$LastPulseEvccData - now is:$($EvccData.Connected)"
$MessageDone = $True
Watch-VolvoCar -Token $Token
}


}else{
Write-LogEntry -Severity 1 -Message 'Evcc data not found or not reachable'

Expand All @@ -221,8 +235,10 @@ Function Start-Volvo4Evcc
Write-LogEntry -Severity 0 -Message "Just a Evcc pull and token test no action taken - Token valid for another : $ValidFor minutes"
}

#Save last run
$LastPulseEvccData = $EvccData.Connected
Start-Sleep -Seconds $Seconds

}while ($True)

}
}
2 changes: 1 addition & 1 deletion internal/internal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ Function Update-SunHours
$MinSocValue = $Global:Config.'Weather.SunHoursMinsocMedium'
}

$ResultSetNewMinSoc = Invoke-RestMethod -Uri "$($Global:Config.'Url.Evcc')/api/vehicles/$($TargetVehicle.Name)/minsoc/$MinSocValue)" -Method Post
$ResultSetNewMinSoc = Invoke-RestMethod -Uri "$($Global:Config.'Url.Evcc')/api/vehicles/$($TargetVehicle.Name)/minsoc/$MinSocValue" -Method Post

}elseif(($TotalSunHours / $Global:Config.'Weather.SunHoursDaysDevider') -lt $Global:Config.'Weather.SunHoursMedium'){
Write-LogEntry -Severity 0 -Message "Weather - Not enough sun"
Expand Down
6 changes: 3 additions & 3 deletions start.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#Load the module
Import-Module "$($pwd.path)/volvo4evcc/Volvo4evcc.psd1"
Import-Module "$($pwd.path)/Volvo4evcc/Volvo4evcc.psd1"
Import-Module "DnsClient-PS"

#Kill any running process that is the same
If ($PSVersionTable.Platform -like "Unix*"){
Get-Process 'pwsh' | Where-Object -FilterScript {$_.Commandline -like "*volvo4evcc/start.ps1" -and $_.id -ne $pid } | Stop-Process -Force
Get-Process 'pwsh' | Where-Object -FilterScript {$_.Commandline -like "*Volvo4evcc/start.ps1" -and $_.id -ne $pid } | Stop-Process -Force
}

If ($PSVersionTable.Platform -like "Win*"){
Get-Process 'pwsh' | Where-Object -FilterScript {$_.Commandline -like "*volvo4evcc/start.ps1" -and $_.id -ne $pid } | Stop-Process -Force
Get-Process 'pwsh' | Where-Object -FilterScript {$_.Commandline -like "*Volvo4evcc/start.ps1" -and $_.id -ne $pid } | Stop-Process -Force
}

Start-Volvo4Evcc

0 comments on commit 7286252

Please sign in to comment.