-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of remote control interface
- Loading branch information
Showing
11 changed files
with
288 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
@import "tailwindcss/utilities"; | ||
|
||
/* This file is for your main application CSS */ | ||
|
||
body { | ||
touch-action: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
defmodule MinettiUi.FakeState do | ||
use GenServer | ||
|
||
@valid_modes [:cool, :heat, :dry, :fan_only, :auto, :off] | ||
|
||
# Client | ||
def start_link(_), | ||
do: | ||
GenServer.start_link( | ||
__MODULE__, | ||
%{mode: :off, temperature: 20.0, fan_speed: :auto, on_timer: nil, off_timer: nil}, | ||
name: __MODULE__ | ||
) | ||
|
||
def state, do: GenServer.call(__MODULE__, :state) | ||
|
||
def set_mode(mode) when mode in @valid_modes, | ||
do: GenServer.call(__MODULE__, {:set_mode, mode}) | ||
|
||
def temperature_up, do: GenServer.call(__MODULE__, :temperature_up) | ||
def temperature_down, do: GenServer.call(__MODULE__, :temperature_down) | ||
def cycle_fan_speed, do: GenServer.call(__MODULE__, :cycle_fan_speed) | ||
|
||
def swing, do: GenServer.cast(__MODULE__, :swing) | ||
def vertical_direction, do: GenServer.cast(__MODULE__, :vertical_direction) | ||
|
||
# Server | ||
@impl GenServer | ||
def init(state), do: {:ok, state} | ||
|
||
@impl GenServer | ||
def handle_call(:state, _from, state), do: {:reply, state, state} | ||
|
||
def handle_call({:set_mode, mode}, _from, state) when mode in [:dry, :auto] do | ||
state = %{state | mode: mode, fan_speed: :auto} | ||
schedule_apply() | ||
{:reply, state, state} | ||
end | ||
|
||
def handle_call({:set_mode, mode}, _from, state) do | ||
state = %{state | mode: mode} | ||
schedule_apply() | ||
{:reply, state, state} | ||
end | ||
|
||
def handle_call(_command, _from, %{mode: :off} = state), do: {:reply, state, state} | ||
|
||
def handle_call(:temperature_up, _from, %{temperature: temperature} = state) | ||
when temperature >= 30, | ||
do: {:reply, state, state} | ||
|
||
def handle_call(:temperature_up, _from, %{temperature: temperature} = state) do | ||
state = %{state | temperature: temperature + 0.5} | ||
schedule_apply() | ||
{:reply, state, state} | ||
end | ||
|
||
def handle_call(:temperature_down, _from, %{temperature: temperature} = state) | ||
when temperature <= 16, | ||
do: {:reply, state, state} | ||
|
||
def handle_call(:temperature_down, _from, %{temperature: temperature} = state) do | ||
state = %{state | temperature: temperature - 0.5} | ||
schedule_apply() | ||
{:reply, state, state} | ||
end | ||
|
||
def handle_call(:cycle_fan_speed, _from, %{mode: mode} = state) when mode in [:dry, :auto], | ||
do: {:reply, state, state} | ||
|
||
def handle_call(:cycle_fan_speed, _from, %{fan_speed: fan_speed} = state) do | ||
state = %{state | fan_speed: next_fan_speed(fan_speed)} | ||
schedule_apply() | ||
{:reply, state, state} | ||
end | ||
|
||
@impl GenServer | ||
def handle_cast(:swing, state) do | ||
{:noreply, state} | ||
end | ||
|
||
def handle_cast(:vertical_direction, state) do | ||
{:noreply, state} | ||
end | ||
|
||
@impl GenServer | ||
def handle_info(:apply, state) do | ||
Phoenix.PubSub.broadcast(MinettiUi.PubSub, "state", {:state_changed, state}) | ||
{:noreply, state} | ||
end | ||
|
||
defp fan_speed_order, do: [:auto, :quiet, :low, :weak, :strong, :super] | ||
|
||
defp next_fan_speed(current_speed), | ||
do: | ||
fan_speed_order() | ||
|> Stream.cycle() | ||
|> Stream.drop_while(&(&1 != current_speed)) | ||
|> Enum.at(1) | ||
|
||
defp schedule_apply, do: send(self(), :apply) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.