Packages

A Gleam library to write and run Home Assistant automations.

Current section

Files

Jump to
glome src glome@homeassistant@environment.erl
Raw

src/glome@homeassistant@environment.erl

-module(glome@homeassistant@environment).
-compile(no_auto_import).
-export([get_host/0, get_port/0, get_access_token/0, get_ha_supervisor_token/0, get_env/1]).
-export_type([configuration/0]).
-type configuration() :: {configuration,
binary(),
integer(),
glome@core@authentication:access_token()}.
-spec get_host() -> gleam@option:option(binary()).
get_host() ->
_pipe = system:get_var(<<"HOST"/utf8>>),
gleam@option:from_result(_pipe).
-spec get_port() -> gleam@option:option(integer()).
get_port() ->
_pipe = system:get_var(<<"PORT"/utf8>>),
_pipe@1 = gleam@result:then(_pipe, fun gleam@int:parse/1),
gleam@option:from_result(_pipe@1).
-spec get_access_token() -> gleam@option:option(glome@core@authentication:access_token()).
get_access_token() ->
_pipe = system:get_var(<<"ACCESS_TOKEN"/utf8>>),
_pipe@1 = gleam@option:from_result(_pipe),
gleam@option:map(_pipe@1, fun(A) -> {access_token, A} end).
-spec get_ha_supervisor_token() -> gleam@option:option(glome@core@authentication:access_token()).
get_ha_supervisor_token() ->
_pipe = system:get_var(<<"SUPERVISOR_TOKEN"/utf8>>),
_pipe@1 = gleam@option:from_result(_pipe),
gleam@option:map(_pipe@1, fun(A) -> {access_token, A} end).
-spec get_env(binary()) -> {ok, binary()} | {error, nil}.
get_env(A) ->
system:get_var(A).