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, "/")
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue