-
Notifications
You must be signed in to change notification settings - Fork 2
/
Get-Locations.ps1
40 lines (33 loc) · 1.75 KB
/
Get-Locations.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<# Add rows for each pet flap you have, and where it leads.
Format is:
( device_id, "location-inbound", "location-outbound", "name-of-petflap" )
for example:
( 123456, "house", "garden", "backdoor")
leave the final $null row (this makes sure it works when you've manually set pet's inside/outside state)
Find your flap IDs with: .\Get-SureFlapDevice.ps1 | ?{$_.product_id -gt 1} | Select id, name
#>
$flaps =
( 151961, "garden room", "outside", "garden room" ),
( 166844, "garage", "outside", "garage" ),
( 113430, "house", "garage", "utility" ),
( $null, "[inside]", "[outside]","") | % { [PSCustomObject]@{id = $_[0]; in = $_[1]; out = $_[2]; name = $_[3] } }
$flapColumns= $flaps[0].PSObject.Properties.name
# --------------------------------------------------------------------------------
$sureFlapObject = .\Get-SureFlapPet.ps1
$petInfo = @( )
ForEach ($pet in $sureFlapObject)
{
$sinceDate = [DateTime]::ParseExact($pet.position.since, 'yyyy-MM-ddTHH:mm:ss+00:00', $null)
$duration = New-TimeSpan -Start $sinceDate
# where from SureFlap API: 1 is coming in, 2 = going out
# find the details of the flap from the device_id to determine where the pet is
$matchingFlap = $flaps | ?{$_.id -eq $pet.position.device_id} | % { $_ }
$location = $matchingFlap.$($flapColumns[$pet.position.where])
$petObject = New-Object -TypeName PSObject
$petObject | Add-Member -Name 'Name' -MemberType Noteproperty -Value $pet.name
$petObject | Add-Member -Name 'Location' -MemberType Noteproperty -Value $location
$petObject | Add-Member -Name 'Since' -MemberType Noteproperty -Value ("{0:dd}-{0:MMM} {0:t}" -f $sinceDate)
$petObject | Add-Member -Name 'Duration' -MemberType Noteproperty -Value ("{0:%d}d {0:hh}h {0:mm}m" -f $duration)
$petInfo += $petObject
}
$petInfo