Compare commits

..

1 Commits

Author SHA1 Message Date
neri 5b173917be feat: report last scanned token to home assistant 2024-07-09 19:25:42 +02:00
1 changed files with 11 additions and 6 deletions

View File

@ -37,7 +37,8 @@ api:
key: $api_enckey
ota:
password: $ota_password
- platform: esphome
password: $ota_password
wifi:
ssid: $wifi_ssid
@ -65,6 +66,7 @@ http_request:
useragent: esphome
timeout: 2s
id: http_request_data
verify_ssl: false
globals:
- id: my_token
@ -92,10 +94,10 @@ rc522_spi:
- text.set:
id: ${name_of_board}_letzter_token
value: !lambda return id(my_tag);
- delay: 2s
# login to vault with role_id to fetch short lived token
- http_request.post:
url: https://vault.ctdo.de/v1/auth/approle/login
verify_ssl: false
headers:
Content-Type: application/json
json:
@ -105,25 +107,26 @@ rc522_spi:
# fetch token from response, store into my_token
then:
- lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
json::parse_json(body, [](JsonObject root) -> bool {
id(my_token) = (const char*) root["auth"]["client_token"];
return true;
});
# use the token to get json of scanned tag from vault
- http_request.get:
url: !lambda |-
return ((std::string) "https://vault.ctdo.de/v1/maschinenlock/" + id(my_tag));
verify_ssl: false
headers:
X-Vault-Token: !lambda return id(my_token).c_str();
on_response:
then:
- if:
condition:
lambda: 'return status_code == 200;'
lambda: 'return response->status_code == 200;'
then: # when found, check if machine is allowed, turn on output or blink LED red
- lambda: |-
json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
json::parse_json(body, [](JsonObject root) -> bool {
id(may_switch_output) = root["data"]["mlock-$name_of_board"];
return true;
});
- if:
condition:
@ -226,6 +229,8 @@ text:
id: ${name_of_board}_letzte_entsperrung
optimistic: true
mode: text
text:
- platform: template
name: "$name_of_board Zuletzt Gelesener Token"
id: ${name_of_board}_letzter_token