Add refresh interval to EspHome
This commit is contained in:
parent
54db9ac551
commit
fb283ee4ba
@ -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.
|
||||
```
|
||||
|
||||
@ -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} />;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user