Add Weather integration adapter
Implements testConnection against wttr.in's JSON API using the configured location, no API key required. listResources is intentionally omitted since weather conditions don't map to the resource-health model. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
This commit is contained in:
parent
907f5deb5f
commit
1540380442
2 changed files with 21 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import { docker } from './docker.js'
|
||||||
import { proxmox } from './proxmox.js'
|
import { proxmox } from './proxmox.js'
|
||||||
import { netbird } from './netbird.js'
|
import { netbird } from './netbird.js'
|
||||||
import { cloudflare } from './cloudflare.js'
|
import { cloudflare } from './cloudflare.js'
|
||||||
|
import { weather } from './weather.js'
|
||||||
|
|
||||||
const notImplemented: IntegrationAdapter = {
|
const notImplemented: IntegrationAdapter = {
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
|
@ -18,5 +19,5 @@ export const adapterRegistry: Record<IntegrationType, IntegrationAdapter> = {
|
||||||
netbird,
|
netbird,
|
||||||
cloudflare,
|
cloudflare,
|
||||||
aws: notImplemented,
|
aws: notImplemented,
|
||||||
weather: notImplemented,
|
weather,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
backend/src/integrations/weather.ts
Normal file
19
backend/src/integrations/weather.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import type { IntegrationAdapter } from './types.js'
|
||||||
|
|
||||||
|
export const weather: IntegrationAdapter = {
|
||||||
|
async testConnection(config) {
|
||||||
|
const location = config.location
|
||||||
|
if (!location) return { ok: false, message: 'Missing location' }
|
||||||
|
try {
|
||||||
|
const res = await fetch(`https://wttr.in/${encodeURIComponent(location)}?format=j1`, {
|
||||||
|
headers: { 'User-Agent': 'curl' },
|
||||||
|
})
|
||||||
|
if (!res.ok) return { ok: false, message: `HTTP ${res.status}` }
|
||||||
|
const body = (await res.json()) as { current_condition?: unknown[] }
|
||||||
|
if (!body.current_condition?.length) return { ok: false, message: 'Location not found' }
|
||||||
|
return { ok: true, message: 'Connected' }
|
||||||
|
} catch (err) {
|
||||||
|
return { ok: false, message: err instanceof Error ? err.message : 'Connection failed' }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue