fix(deye): send both measurements in one message
All checks were successful
Build / build (push) Successful in 3m14s
All checks were successful
Build / build (push) Successful in 3m14s
This commit is contained in:
parent
7fba9080b4
commit
2350a7859d
1 changed files with 23 additions and 9 deletions
|
@ -62,7 +62,7 @@ defmodule WeewxProxy.Modbus.Deye do
|
||||||
full_topic = Enum.join(topic, "/")
|
full_topic = Enum.join(topic, "/")
|
||||||
parsed_message = parse_message(full_topic, publish)
|
parsed_message = parse_message(full_topic, publish)
|
||||||
|
|
||||||
:ok = handle_reading(full_topic, parsed_message)
|
state = handle_reading(full_topic, parsed_message, state)
|
||||||
|
|
||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
@ -82,16 +82,30 @@ defmodule WeewxProxy.Modbus.Deye do
|
||||||
|
|
||||||
defp parse_message(_topic, _message), do: nil
|
defp parse_message(_topic, _message), do: nil
|
||||||
|
|
||||||
@spec handle_reading(String.t(), float() | nil) :: :ok
|
@spec handle_reading(String.t(), float() | nil, {:day | :active, float()}) :: {:day | :active, float()} | nil
|
||||||
defp handle_reading(_topic, nil), do: :ok
|
defp handle_reading(_topic, nil, state), do: state
|
||||||
|
|
||||||
defp handle_reading("deye/day_energy", reading) do
|
defp handle_reading("deye/day_energy", reading, {:active, active}) do
|
||||||
data = %{dateTime: Utils.utc_timestamp(), solarEnergyDay: reading}
|
timestamp = DateTime.utc_now() |> DateTime.to_unix()
|
||||||
Publisher.publish("weewx/ingest_si", data)
|
data = %{dateTime: timestamp, solarEnergyDay: reading, solarEnergyActive: active}
|
||||||
|
:ok = Publisher.publish("weewx/ingest_si", data)
|
||||||
|
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
defp handle_reading("deye/ac/active_power", reading) do
|
defp handle_reading("deye/day_energy", reading, _other) do
|
||||||
data = %{dateTime: Utils.utc_timestamp(), solarEnergyActive: reading}
|
{:day, reading}
|
||||||
Publisher.publish("weewx/ingest_si", data)
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue