Add refresh interval to EspHome

This commit is contained in:
RoboMagus 2024-03-11 13:11:43 +01:00
parent 54db9ac551
commit fb283ee4ba
2 changed files with 8 additions and 1 deletions

View File

@ -13,4 +13,5 @@ Allowed fields: `["total", "online", "offline", "unknown"]`.
widget:
type: esphome
url: http://esphome.host.or.ip:port
refreshInterval: 30000 # optional - in milliseconds, defaults to 30s. Minimal allowed: 10000.
```

View File

@ -4,11 +4,17 @@ import Block from "components/services/widget/block";
import Container from "components/services/widget/container";
import useWidgetAPI from "utils/proxy/use-widget-api";
const defaultInterval = 30000;
const minRefreshInterval = 10000;
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: resultData, error: resultError } = useWidgetAPI(widget);
const { refreshInterval = defaultInterval } = widget;
const { data: resultData, error: resultError } = useWidgetAPI(widget, "devices", {
refreshInterval: Math.max(minRefreshInterval, refreshInterval),
});
if (resultError) {
return <Container service={service} error={resultError} />;