fix(deye): send both measurements in one message
All checks were successful
Build / build (push) Successful in 3m14s

This commit is contained in:
Daniel Kempkens 2024-07-15 21:14:50 +02:00
parent 7fba9080b4
commit 2350a7859d
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM

View file

@ -62,7 +62,7 @@ defmodule WeewxProxy.Modbus.Deye do
full_topic = Enum.join(topic, "/")
parsed_message = parse_message(full_topic, publish)
:ok = handle_reading(full_topic, parsed_message)
state = handle_reading(full_topic, parsed_message, state)
{:ok, state}
end
@ -82,16 +82,30 @@ defmodule WeewxProxy.Modbus.Deye do
defp parse_message(_topic, _message), do: nil
@spec handle_reading(String.t(), float() | nil) :: :ok
defp handle_reading(_topic, nil), do: :ok
@spec handle_reading(String.t(), float() | nil, {:day | :active, float()}) :: {:day | :active, float()} | nil
defp handle_reading(_topic, nil, state), do: state
defp handle_reading("deye/day_energy", reading) do
data = %{dateTime: Utils.utc_timestamp(), solarEnergyDay: reading}
Publisher.publish("weewx/ingest_si", data)
defp handle_reading("deye/day_energy", reading, {:active, active}) do
timestamp = DateTime.utc_now() |> DateTime.to_unix()
data = %{dateTime: timestamp, solarEnergyDay: reading, solarEnergyActive: active}
:ok = Publisher.publish("weewx/ingest_si", data)
nil
end
defp handle_reading("deye/ac/active_power", reading) do
data = %{dateTime: Utils.utc_timestamp(), solarEnergyActive: reading}
Publisher.publish("weewx/ingest_si", data)
defp handle_reading("deye/day_energy", reading, _other) do
{:day, reading}
end
defp handle_reading("deye/ac/active_power", reading, {:day, day}) do
timestamp = DateTime.utc_now() |> DateTime.to_unix()
data = %{dateTime: timestamp, solarEnergyDay: day, solarEnergyActive: reading}
:ok = Publisher.publish("weewx/ingest_si", data)
nil
end
defp handle_reading("deye/ac/active_power", reading, _other) do
{:active, reading}
end
end