diff --git a/devices/basement_bathroom_light_fan.yaml b/devices/basement_bathroom_light_fan.yaml index 58a19fe..7fe6353 100644 --- a/devices/basement_bathroom_light_fan.yaml +++ b/devices/basement_bathroom_light_fan.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Basement Bathroom Light and Fan platform: ESP8266 board: esp01_1m - ip_address: !secret basement_bathroom_light_fan_ip - ota_pwd: !secret basement_bathroom_light_fan_ota_pwd - api_pwd: !secret basement_bathroom_light_fan_api_pwd - ap_wifi_pwd: !secret basement_bathroom_light_fan_ap_wifi_pwd + ip_address: !secret basement-bathroom-light-fan-ip + ota_pwd: !secret basement-bathroom-light-fan-ota-pwd + api_pwd: !secret basement-bathroom-light-fan-api-pwd + ap_wifi_pwd: !secret basement-bathroom-light-fan-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/basement_bathroom_sensor.yaml b/devices/basement_bathroom_sensor.yaml index 4cb8591..3b7e9cf 100644 --- a/devices/basement_bathroom_sensor.yaml +++ b/devices/basement_bathroom_sensor.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Basement Bathroom Sensor platform: ESP8266 board: d1_mini - ip_address: !secret basement_bathroom_sensor_ip - ota_pwd: !secret basement_bathroom_sensor_ota_pwd - api_pwd: !secret basement_bathroom_sensor_api_pwd - ap_wifi_pwd: !secret basement_bathroom_sensor_ap_wifi_pwd + ip_address: !secret basement-bathroom-sensor-ip + ota_pwd: !secret basement-bathroom-sensor-ota-pwd + api_pwd: !secret basement-bathroom-sensor-api-pwd + ap_wifi_pwd: !secret basement-bathroom-sensor-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/basement_bathroom_shower_light_heater.yaml b/devices/basement_bathroom_shower_light_heater.yaml index 83eb0d5..aaa95af 100644 --- a/devices/basement_bathroom_shower_light_heater.yaml +++ b/devices/basement_bathroom_shower_light_heater.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Basement Bathroom Shower Light and Heater platform: ESP8266 board: esp01_1m - ip_address: !secret basement_bathroom_shower_light_heater_ip - ota_pwd: !secret basement_bathroom_shower_light_heater_ota_pwd - api_pwd: !secret basement_bathroom_shower_light_heater_api_pwd - ap_wifi_pwd: !secret basement_bathroom_shower_light_heater_ap_wifi_pwd + ip_address: !secret basement-bathroom-shower-light-heater-ip + ota_pwd: !secret basement-bathroom-shower-light-heater-ota-pwd + api_pwd: !secret basement-bathroom-shower-light-heater-api-pwd + ap_wifi_pwd: !secret basement-bathroom-shower-light-heater-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/basement_stair_lights_1.yaml b/devices/basement_stair_lights_1.yaml index 54291e9..41d9f88 100644 --- a/devices/basement_stair_lights_1.yaml +++ b/devices/basement_stair_lights_1.yaml @@ -1,10 +1,10 @@ substitutions: device_id: basement_stair_lights device_name: Basement Stair Lights - ip_address: !secret basement_stair_lights_ip - ota_pwd: !secret basement_stair_lights_ota_pwd - api_pwd: !secret basement_stair_lights_api_pwd - ap_wifi_pwd: !secret basement_stair_lights_ap_wifi_pwd + ip_address: !secret basement-stair-lights-ip + ota_pwd: !secret basement-stair-lights-ota-pwd + api_pwd: !secret basement-stair-lights-api-pwd + ap_wifi_pwd: !secret basement-stair-lights-ap-pwd script: - id: double_click diff --git a/devices/basement_stair_lights_2.yaml b/devices/basement_stair_lights_2.yaml index 96ebf47..c7edb28 100644 --- a/devices/basement_stair_lights_2.yaml +++ b/devices/basement_stair_lights_2.yaml @@ -1,10 +1,10 @@ substitutions: device_id: basement_stair_lights_2 device_name: Basement Stair Lights 2 - ip_address: !secret basement_stair_lights_2_ip - ota_pwd: !secret basement_stair_lights_2_ota_pwd - api_pwd: !secret basement_stair_lights_2_api_pwd - ap_wifi_pwd: !secret basement_stair_lights_2_ap_wifi_pwd + ip_address: !secret basement-stair-lights-2-ip + ota_pwd: !secret basement-stair-lights-2-ota-pwd + api_pwd: !secret basement-stair-lights-2-api-pwd + ap_wifi_pwd: !secret basement-stair-lights-2-ap-pwd script: - id: double_click diff --git a/devices/coffee_maker.yaml b/devices/coffee_maker.yaml index 980d900..f4c605b 100644 --- a/devices/coffee_maker.yaml +++ b/devices/coffee_maker.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Coffee Maker platform: ESP8266 board: nodemcuv2 - ip_address: !secret coffee_maker_ip - ota_pwd: !secret coffee_maker_ota_pwd - api_pwd: !secret coffee_maker_api_pwd - ap_wifi_pwd: !secret coffee_maker_ap_wifi_pwd + ip_address: !secret coffee-maker-ip + ota_pwd: !secret coffee-maker-ota-pwd + api_pwd: !secret coffee-maker-api-pwd + ap_wifi_pwd: !secret coffee-maker-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/computer_light.yaml b/devices/computer_light.yaml index d700a0c..c57d1e0 100644 --- a/devices/computer_light.yaml +++ b/devices/computer_light.yaml @@ -1,10 +1,10 @@ substitutions: device_id: computer_light device_name: Computer Light - ip_address: !secret computer_light_ip - ota_pwd: !secret computer_light_ota_pwd - api_pwd: !secret computer_light_api_pwd - ap_wifi_pwd: !secret computer_light_ap_wifi_pwd + ip_address: !secret computer-light-ip + ota_pwd: !secret computer-light-ota-pwd + api_pwd: !secret computer-light-api-pwd + ap_wifi_pwd: !secret computer-light-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/dining_room_light.yaml b/devices/dining_room_light.yaml index 18c9d6e..8dfa281 100644 --- a/devices/dining_room_light.yaml +++ b/devices/dining_room_light.yaml @@ -1,10 +1,10 @@ substitutions: device_id: dining_room_light device_name: Dining Room Light - ip_address: !secret dining_room_light_ip - ota_pwd: !secret dining_room_light_ota_pwd - api_pwd: !secret dining_room_light_api_pwd - ap_wifi_pwd: !secret dining_room_light_ap_wifi_pwd + ip_address: !secret dining-room-light-ip + ota_pwd: !secret dining-room-light-ota-pwd + api_pwd: !secret dining-room-light-api-pwd + ap_wifi_pwd: !secret dining-room-light-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/family_room_light.yaml b/devices/family_room_light.yaml index dfea840..f09e1f3 100644 --- a/devices/family_room_light.yaml +++ b/devices/family_room_light.yaml @@ -1,10 +1,10 @@ substitutions: device_id: family_room_light device_name: Family Room Light - ip_address: !secret family_room_light_ip - ota_pwd: !secret family_room_light_ota_pwd - api_pwd: !secret family_room_light_api_pwd - ap_wifi_pwd: !secret family_room_light_ap_wifi_pwd + ip_address: !secret family-room-light-ip + ota_pwd: !secret family-room-light-ota-pwd + api_pwd: !secret family-room-light-api-pwd + ap_wifi_pwd: !secret family-room-light-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/fire_pit_fountain.yaml b/devices/fire_pit_fountain.yaml index 35f55fe..adc3c53 100644 --- a/devices/fire_pit_fountain.yaml +++ b/devices/fire_pit_fountain.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Fire Pit and Fountain platform: ESP8266 board: d1_mini - ip_address: !secret fire_pit_fountain_ip - ota_pwd: !secret fire_pit_fountain_ota_pwd - api_pwd: !secret fire_pit_fountain_api_pwd - ap_wifi_pwd: !secret fire_pit_fountain_ap_wifi_pwd + ip_address: !secret fire-pit-fountain-ip + ota_pwd: !secret fire-pit-fountain-ota-pwd + api_pwd: !secret fire-pit-fountain-api-pwd + ap_wifi_pwd: !secret fire-pit-fountain-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/front_entry_lights_1.yaml b/devices/front_entry_lights_1.yaml index 84aed74..f36b035 100644 --- a/devices/front_entry_lights_1.yaml +++ b/devices/front_entry_lights_1.yaml @@ -1,10 +1,10 @@ substitutions: device_id: front_entry_lights device_name: Front Entry Lights - ip_address: !secret front_entry_lights_ip - ota_pwd: !secret front_entry_lights_ota_pwd - api_pwd: !secret front_entry_lights_api_pwd - ap_wifi_pwd: !secret front_entry_lights_ap_wifi_pwd + ip_address: !secret front-entry-lights-ip + ota_pwd: !secret front-entry-lights-ota-pwd + api_pwd: !secret front-entry-lights-api-pwd + ap_wifi_pwd: !secret front-entry-lights-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/front_entry_lights_2.yaml b/devices/front_entry_lights_2.yaml index 16ec722..ada363a 100644 --- a/devices/front_entry_lights_2.yaml +++ b/devices/front_entry_lights_2.yaml @@ -1,10 +1,10 @@ substitutions: device_id: front_entry_lights_2 device_name: Front Entry Lights 2 - ip_address: !secret front_entry_lights_2_ip - ota_pwd: !secret front_entry_lights_2_ota_pwd - api_pwd: !secret front_entry_lights_2_api_pwd - ap_wifi_pwd: !secret front_entry_lights_2_ap_wifi_pwd + ip_address: !secret front-entry-lights_2-ip + ota_pwd: !secret front-entry-lights-2-ota-pwd + api_pwd: !secret front-entry-lights-2-api-pwd + ap_wifi_pwd: !secret front-entry-lights-2-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml diff --git a/devices/front_lights.yaml b/devices/front_lights.yaml index 588f298..db43ef8 100644 --- a/devices/front_lights.yaml +++ b/devices/front_lights.yaml @@ -1,10 +1,10 @@ substitutions: device_id: front_lights device_name: Front Lights - ip_address: !secret front_lights_ip - ota_pwd: !secret front_lights_ota_pwd - api_pwd: !secret front_lights_api_pwd - ap_wifi_pwd: !secret front_lights_ap_wifi_pwd + ip_address: !secret front-lights-ip + ota_pwd: !secret front-lights-ota-pwd + api_pwd: !secret front-lights-api-pwd + ap_wifi_pwd: !secret front-lights-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/garage_fridge.yaml b/devices/garage_fridge.yaml index 354bfc0..904883d 100644 --- a/devices/garage_fridge.yaml +++ b/devices/garage_fridge.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Garage Fridge platform: ESP8266 board: nodemcuv2 - ip_address: !secret garage_fridge_ip - ota_pwd: !secret garage_fridge_ota_pwd - api_pwd: !secret garage_fridge_api_pwd - ap_wifi_pwd: !secret garage_fridge_ap_wifi_pwd + ip_address: !secret garage-fridge-ip + ota_pwd: !secret garage-fridge-ota-pwd + api_pwd: !secret garage-fridge-api-pwd + ap_wifi_pwd: !secret garage-fridge-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/kitchen_bar_lights.yaml b/devices/kitchen_bar_lights.yaml index f9fba2c..ef05a7c 100644 --- a/devices/kitchen_bar_lights.yaml +++ b/devices/kitchen_bar_lights.yaml @@ -1,10 +1,10 @@ substitutions: device_id: kitchen_bar_lights device_name: Kitchen Bar Lights - ip_address: !secret kitchen_bar_lights_ip - ota_pwd: !secret kitchen_bar_lights_ota_pwd - api_pwd: !secret kitchen_bar_lights_api_pwd - ap_wifi_pwd: !secret kitchen_bar_lights_ap_wifi_pwd + ip_address: !secret kitchen-bar-lights-ip + ota_pwd: !secret kitchen-bar-lights-ota-pwd + api_pwd: !secret kitchen-bar-lights-api-pwd + ap_wifi_pwd: !secret kitchen-bar-lights-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/kitchen_table_light.yaml b/devices/kitchen_table_light.yaml index c1431b5..c668c09 100644 --- a/devices/kitchen_table_light.yaml +++ b/devices/kitchen_table_light.yaml @@ -1,10 +1,10 @@ substitutions: device_id: kitchen_table_light device_name: Kitchen Table Light - ip_address: !secret kitchen_table_light_ip - ota_pwd: !secret kitchen_table_light_ota_pwd - api_pwd: !secret kitchen_table_light_api_pwd - ap_wifi_pwd: !secret kitchen_table_light_ap_wifi_pwd + ip_address: !secret kitchen-table-light-ip + ota_pwd: !secret kitchen-table-light-ota-pwd + api_pwd: !secret kitchen-table-light-api-pwd + ap_wifi_pwd: !secret kitchen-table-light-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/living_room_lights.yaml b/devices/living_room_lights.yaml index efa8a6c..7222f8c 100644 --- a/devices/living_room_lights.yaml +++ b/devices/living_room_lights.yaml @@ -1,10 +1,10 @@ substitutions: device_id: living_room_lights device_name: Living Room Lights - ip_address: !secret living_room_lights_ip - ota_pwd: !secret living_room_lights_ota_pwd - api_pwd: !secret living_room_lights_api_pwd - ap_wifi_pwd: !secret living_room_lights_ap_wifi_pwd + ip_address: !secret living-room-lights-ip + ota_pwd: !secret living-room-lights-ota-pwd + api_pwd: !secret living-room-lights-api-pwd + ap_wifi_pwd: !secret living-room-lights-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/master_bath_fan.yaml b/devices/master_bath_fan.yaml index a304b93..87482f6 100644 --- a/devices/master_bath_fan.yaml +++ b/devices/master_bath_fan.yaml @@ -1,10 +1,10 @@ substitutions: device_id: master_bath_fan device_name: Master Bathroom Fan - ip_address: !secret master_bath_fan_ip - ota_pwd: !secret master_bath_fan_ota_pwd - api_pwd: !secret master_bath_fan_api_pwd - ap_wifi_pwd: !secret master_bath_fan_ap_wifi_pwd + ip_address: !secret master-bath-fan-ip + ota_pwd: !secret master-bath-fan-ota-pwd + api_pwd: !secret master-bath-fan-api-pwd + ap_wifi_pwd: !secret master-bath-fan-ap-pwd fan_wattage: "26.6" packages: diff --git a/devices/master_bath_humidity_temp_sensor.yaml b/devices/master_bath_humidity_temp_sensor.yaml index cda46f5..c277cfa 100644 --- a/devices/master_bath_humidity_temp_sensor.yaml +++ b/devices/master_bath_humidity_temp_sensor.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Master Bathroom Humidity and Temperature Sensor platform: ESP8266 board: d1_mini - ip_address: !secret master_bath_humidity_temp_sensor_ip - ota_pwd: !secret master_bath_humidity_temp_sensor_ota_pwd - api_pwd: !secret master_bath_humidity_temp_sensor_api_pwd - ap_wifi_pwd: !secret master_bath_humidity_temp_sensor_ap_wifi_pwd + ip_address: !secret master-bath-humidity-temp-sensor-ip + ota_pwd: !secret master-bath-humidity-temp-sensor-ota-pwd + api_pwd: !secret master-bath-humidity-temp-sensor-api-pwd + ap_wifi_pwd: !secret master-bath-humidity-temp-sensor-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/master_bath_lights_1.yaml b/devices/master_bath_lights_1.yaml index 5551d0e..e43e8e4 100644 --- a/devices/master_bath_lights_1.yaml +++ b/devices/master_bath_lights_1.yaml @@ -1,10 +1,10 @@ substitutions: device_id: master_bath_lights device_name: Master Bathroom Lights - ip_address: !secret master_bath_lights_ip - ota_pwd: !secret master_bath_lights_ota_pwd - api_pwd: !secret master_bath_lights_api_pwd - ap_wifi_pwd: !secret master_bath_lights_ap_wifi_pwd + ip_address: !secret master-bath-lights-ip + ota_pwd: !secret master-bath-lights-ota-pwd + api_pwd: !secret master-bath-lights-api-pwd + ap_wifi_pwd: !secret master-bath-lights-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/master_bath_lights_2.yaml b/devices/master_bath_lights_2.yaml index 56c5ec9..80997b2 100644 --- a/devices/master_bath_lights_2.yaml +++ b/devices/master_bath_lights_2.yaml @@ -1,10 +1,10 @@ substitutions: device_id: master_bath_lights_2 device_name: Master Bathroom Lights 2 - ip_address: !secret master_bath_lights_2_ip - ota_pwd: !secret master_bath_lights_2_ota_pwd - api_pwd: !secret master_bath_lights_2_api_pwd - ap_wifi_pwd: !secret master_bath_lights_2_ap_wifi_pwd + ip_address: !secret master-bath-lights-2-ip + ota_pwd: !secret master-bath-lights-2-ota-pwd + api_pwd: !secret master-bath-lights-2-api-pwd + ap_wifi_pwd: !secret master-bath-lights-2-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml diff --git a/devices/master_bed.yaml b/devices/master_bed.yaml index 1dc5f53..8b3256e 100644 --- a/devices/master_bed.yaml +++ b/devices/master_bed.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Master Bed platform: ESP8266 board: nodemcuv2 - ip_address: !secret master_bed_ip - ota_pwd: !secret master_bed_ota_pwd - api_pwd: !secret master_bed_api_pwd - ap_wifi_pwd: !secret master_bed_ap_wifi_pwd + ip_address: !secret master-bed-ip + ota_pwd: !secret master-bed-ota-pwd + api_pwd: !secret master-bed-api-pwd + ap_wifi_pwd: !secret master-bed-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/office_light.yaml b/devices/office_light.yaml index 3efaf09..fd8e55a 100644 --- a/devices/office_light.yaml +++ b/devices/office_light.yaml @@ -1,10 +1,10 @@ substitutions: device_id: office_light device_name: Office Light - ip_address: !secret office_light_ip - ota_pwd: !secret office_light_ota_pwd - api_pwd: !secret office_light_api_pwd - ap_wifi_pwd: !secret office_light_ap_wifi_pwd + ip_address: !secret office-light-ip + ota_pwd: !secret office-light-ota-pwd + api_pwd: !secret office-light-api-pwd + ap_wifi_pwd: !secret office-light-ap-pwd packages: feit_dimmer: !include ../packages/feit_dimmer.yaml diff --git a/devices/patio_lights.yaml b/devices/patio_lights.yaml index 6016c57..f5edbdb 100644 --- a/devices/patio_lights.yaml +++ b/devices/patio_lights.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Patio Lights platform: ESP8266 board: d1_mini - ip_address: !secret patio_lights_ip - ota_pwd: !secret patio_lights_ota_pwd - api_pwd: !secret patio_lights_api_pwd - ap_wifi_pwd: !secret patio_lights_ap_wifi_pwd + ip_address: !secret patio-lights-ip + ota_pwd: !secret patio-lights-ota-pwd + api_pwd: !secret patio-lights-api-pwd + ap_wifi_pwd: !secret patio-lights-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/pool_and_patio_lights.yaml b/devices/pool_and_patio_lights.yaml index 35a6aed..998a90f 100644 --- a/devices/pool_and_patio_lights.yaml +++ b/devices/pool_and_patio_lights.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Pool and Patio Lights platform: ESP8266 board: esp01_1m - ip_address: !secret pool_and_patio_lights_ip - ota_pwd: !secret pool_and_patio_lights_ota_pwd - api_pwd: !secret pool_and_patio_lights_api_pwd - ap_wifi_pwd: !secret pool_and_patio_lights_ap_wifi_pwd + ip_address: !secret pool-and-patio-lights-ip + ota_pwd: !secret pool-and-patio-lights-ota-pwd + api_pwd: !secret pool-and-patio-lights-api-pwd + ap_wifi_pwd: !secret pool-and-patio-lights-ap-pwd packages: device_base: !include ../packages/device_base.yaml diff --git a/devices/pool_pumps.yaml b/devices/pool_pumps.yaml index 7bec069..f8df514 100644 --- a/devices/pool_pumps.yaml +++ b/devices/pool_pumps.yaml @@ -3,10 +3,10 @@ substitutions: device_name: Pool Pumps platform: ESP8266 board: modwifi - ip_address: !secret pool_pumps_ip - ota_pwd: !secret pool_pumps_ota_pwd - api_pwd: !secret pool_pumps_api_pwd - ap_wifi_pwd: !secret pool_pumps_ap_wifi_pwd + ip_address: !secret pool-pumps-ip + ota_pwd: !secret pool-pumps-ota-pwd + api_pwd: !secret pool-pumps-api-pwd + ap_wifi_pwd: !secret pool-pumps-ap-pwd packages: device_base: !include ../packages/device_base.yaml @@ -38,7 +38,7 @@ pool_controller: pump: switch_id: pool_pump current_id: pool_pump_current - min_current: 6.45 + min_current: 3.45 max_current: 6.75 max_out_of_range_duration: 5s cleaner: diff --git a/packages/device_base.yaml b/packages/device_base.yaml index b23277a..86ccc50 100644 --- a/packages/device_base.yaml +++ b/packages/device_base.yaml @@ -1,9 +1,9 @@ substitutions: log_level: none - wifi_ssid: !secret wifi_ssid - wifi_password: !secret wifi_password - ip_subnet: !secret ip_subnet - ip_gateway: !secret ip_gateway + wifi_ssid: !secret wifi-ssid + wifi_password: !secret wifi-password + ip_subnet: !secret ip-subnet + ip_gateway: !secret ip-gateway esphome: name: ${device_id} diff --git a/packages/feit_dimmer.yaml b/packages/feit_dimmer.yaml index dd5e38a..d9e9d80 100644 --- a/packages/feit_dimmer.yaml +++ b/packages/feit_dimmer.yaml @@ -10,17 +10,17 @@ external_components: - source: github://cbpowell/ESPSense components: [ espsense ] +packages: + base: !include device_base.yaml + logger: !include logger/logger_no_serial.yaml + uart: !include uart/tuya.yaml + espsense: plugs: - name: ${device_name} power_sensor: power voltage: 120 -packages: - base: !include device_base.yaml - logger: !include logger/logger_no_serial.yaml - uart: !include uart/tuya.yaml - sensor: - platform: total_daily_energy name: ${device_name} diff --git a/scripts/secrets.ps1 b/scripts/secrets.ps1 new file mode 100644 index 0000000..3507d6b --- /dev/null +++ b/scripts/secrets.ps1 @@ -0,0 +1,79 @@ +if ($Args.Count -ne 2 -or ($Args[0] -ne "add" -and $Args[0] -ne "get")) +{ + Write-Output "Invalid parameters" + exit 1 +} + +Add-Type -AssemblyName 'System.Web' + +if (!(Get-InstalledModule -Name powershell-yaml -ErrorAction SilentlyContinue)) +{ + Install-Module -Scope CurrentUser powershell-yaml +} + +$device = $Args[1] +if ($device.Contains("_")) +{ + Write-Output "Invalid device id" + exit 1 +} + +[string[]]$secretsFile = Get-Content $PSScriptRoot\..\secrets.yaml +$yaml = '' +foreach ($line in $secretsFile) { $yaml = $yaml + "`n" + $line } +$secrets = ConvertFrom-YAML $yaml -Ordered + +if ($Args[0] -eq "add") +{ + if ($secrets.Contains("${device}-ip")) + { + Write-Output "Device already exists" + exit 1 + } + + $lastIp = ([IPAddress] "192.168.0.0").GetAddressBytes() + foreach ($key in $secrets.Keys) + { + if ($key.EndsWith("ip")) + { + $ip = ([IPAddress] $secrets.$key).GetAddressBytes() + if ($ip[2] -gt $lastIp[2] -or ($ip[2] -eq $lastIp[2] -and $ip[3] -gt $lastIp[3])) + { + $lastIp = $ip + } + } + } + $nextIp = $lastIp + if ($nextIp[3] -eq 255) + { + $nextIp[3] = 0 + $nextIp[2] += 1 + } + else + { + $nextIp[3] += 1 + } + + $secrets["${device}-ip"] = ([IPAddress]$nextIp).ToString() + $secrets["${device}-api-pwd"] = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) + $secrets["${device}-ota-pwd"] = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) + $secrets["${device}-ap-pwd"] = -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) + + Out-File $PSScriptRoot\..\secrets.yaml -InputObject (ConvertTo-YAML $secrets) +} + +if (!$secrets.Contains("${device}-ip")) +{ + Write-Output "Device not found" + exit 1 +} + +$ip = $secrets["${device}-ip"] +$api = $secrets["${device}-api-pwd"] +$ota = $secrets["${device}-ota-pwd"] +$ap = $secrets["${device}-ap-pwd"] +Write-Output ${device}: +Write-Output " IP Address: ${ip}" +Write-Output " API Password: ${api}" +Write-Output " OTA Password: ${ota}" +Write-Output " AP Password: ${ap}"