ha: export converted us data
All checks were successful
Build / build (push) Successful in 7m36s

This commit is contained in:
Daniel Kempkens 2025-01-05 19:10:47 +01:00
parent f629f4a019
commit 4538221d41
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM

View file

@ -24,7 +24,15 @@ defmodule WeewxProxy.HTTP.Ecowitt do
_ = Logger.debug("Removing keys: `#{inspect(sdr_keys)}'") _ = Logger.debug("Removing keys: `#{inspect(sdr_keys)}'")
partial_data = Map.drop(data, sdr_keys) partial_data = Map.drop(data, sdr_keys)
:ok = Publisher.publish("weewx/ingest_us", partial_data) :ok = Publisher.publish("weewx/ingest_us", partial_data)
Publisher.publish_value_map("hadata/weewx/us", partial_data) :ok = Publisher.publish_value_map("hadata/weewx/us", partial_data)
hadata_si = convert_data_ha(partial_data)
if map_size(hadata_si) > 0 do
Publisher.publish_value_map("hadata/weewx/si", hadata_si)
else
:ok
end
else else
_ = Logger.error("Not publishing record because data appears invalid: #{inspect(data)}") _ = Logger.error("Not publishing record because data appears invalid: #{inspect(data)}")
:ok :ok
@ -121,4 +129,17 @@ defmodule WeewxProxy.HTTP.Ecowitt do
defp valid_data?(data) do defp valid_data?(data) do
Map.has_key?(data, :outTemp) and is_number(data.outTemp) Map.has_key?(data, :outTemp) and is_number(data.outTemp)
end end
@spec convert_data_ha(map()) :: map()
defp convert_data_ha(data) do
result = %{}
result = if Map.has_key?(data, :outTemp), do: Map.put(result, :outTemp, (data.outTemp - 32.0) / 1.8), else: result
result = if Map.has_key?(data, :outHumidity), do: Map.put(result, :outHumidity, data.outHumidity), else: result
result = if Map.has_key?(data, :inTemp), do: Map.put(result, :inTemp, (data.inTemp - 32.0) / 1.8), else: result
result = if Map.has_key?(data, :inHumidity), do: Map.put(result, :inHumidity, data.inHumidity), else: result
result
end
end end