From 13f3a1167c4145ca17db2b036bc3bf93be45c08d Mon Sep 17 00:00:00 2001 From: Mikko Ahlroth Date: Thu, 17 Feb 2022 20:46:26 +0200 Subject: [PATCH] Fix for new version of pump firmware --- config/runtime.exs | 26 ++++++++++++++----- lib/geo_therminator/pump_api/device/api.ex | 12 +++++++-- lib/geo_therminator/pump_api/device/device.ex | 2 ++ mix.exs | 2 +- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 02d41e3..0940d54 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -58,6 +58,19 @@ config :geo_therminator, # "REG_VALUE_STATUS_OFF" => 100 100 => :off }, + api_opstat_bitmask_mapping: %{ + 1 => :hand_operated, + 2 => :defrost, + 4 => :hot_water, + 8 => :heating, + 16 => :active_cooling, + 32 => :pool, + 64 => :anti_legionella, + 128 => :passive_cooling, + 512 => :standby, + 1024 => :idle, + 2048 => :off + }, api_device_reg_set_url: get_env( "API_DEVICE_REG_SET_URL", @@ -67,12 +80,13 @@ config :geo_therminator, api_device_reg_set_client_id: get_env("API_DEVICE_REG_SET_CLIENT_ID"), api_refresh: 10_000 -# config/runtime.exs is executed for all environments, including -# during releases. It is executed after compilation and before the -# system starts, so it is typically used to load production configuration -# and secrets from environment variables or elsewhere. Do not define -# any compile-time configuration in here, as it won't be applied. -# The block below contains prod specific runtime configuration. +if config_env() == :dev do + config :geo_therminator, GeoTherminatorWeb.Endpoint, + http: [ + port: String.to_integer(System.get_env("PORT") || "4000") + ] +end + if config_env() == :prod do # The secret key base is used to sign/encrypt cookies and other secrets. # A default value is used in config/dev.exs and config/test.exs but you diff --git a/lib/geo_therminator/pump_api/device/api.ex b/lib/geo_therminator/pump_api/device/api.ex index 3c7ff3c..665dd35 100644 --- a/lib/geo_therminator/pump_api/device/api.ex +++ b/lib/geo_therminator/pump_api/device/api.ex @@ -103,10 +103,18 @@ defmodule GeoTherminator.PumpAPI.Device.API do end) priority_register = find_register(registers, "REG_OPERATIONAL_STATUS_PRIO1") - mapping = Application.get_env(:geo_therminator, :api_opstat_mapping) + priority_register_fallback = find_register(registers, "REG_OPERATIONMODE") + + {mapping, register} = + if not is_nil(priority_register) do + {Application.get_env(:geo_therminator, :api_opstat_mapping), priority_register} + else + {Application.get_env(:geo_therminator, :api_opstat_bitmask_mapping), + priority_register_fallback} + end %Device.OpStat{ - priority: Map.fetch!(mapping, priority_register.register_value) + priority: Map.get(mapping, register.register_value, :unknown) } end diff --git a/lib/geo_therminator/pump_api/device/device.ex b/lib/geo_therminator/pump_api/device/device.ex index 3c263a6..9310a89 100644 --- a/lib/geo_therminator/pump_api/device/device.ex +++ b/lib/geo_therminator/pump_api/device/device.ex @@ -53,6 +53,8 @@ defmodule GeoTherminator.PumpAPI.Device do | :standby | :idle | :off + | :defrost + | :unknown }) end diff --git a/mix.exs b/mix.exs index 14a9bba..7a3f870 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule GeoTherminator.MixProject do def project do [ app: :geo_therminator, - version: "0.1.0", + version: "0.2.0", elixir: "~> 1.12", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:gettext] ++ Mix.compilers(),