create or replace function ems.fn_telemetry_pool_pump_sample(
  p_site_id int,
  p_pump_id int,
  p_measured_at timestamptz,
  p_is_on boolean,
  p_power_w int,
  p_energy_wh_total bigint
)
returns void
language sql
as $fn$
  insert into ems.telemetry_pool_pump (
    site_id,
    pump_id,
    measured_at,
    is_on,
    power_w,
    energy_wh_total
  )
  values (
    p_site_id,
    p_pump_id,
    p_measured_at,
    p_is_on,
    p_power_w,
    p_energy_wh_total
  )
  on conflict (pump_id, measured_at) do nothing;
$fn$;

comment on function ems.fn_telemetry_pool_pump_sample is
  'Insert 1min telemetrie bazénového čerpadla (Shelly Switch.GetStatus: output, apower, aenergy.total). Volá telemetry_collector.poll_pool_pumps.';
