homeweatherapi/src/app.service.ts

17 lines
388 B
TypeScript
Raw Normal View History

2023-09-16 19:45:26 +00:00
import { Injectable, OnApplicationShutdown } from '@nestjs/common';
import WS1080 from './module/ws1080';
@Injectable()
export class AppService implements OnApplicationShutdown {
public station?: WS1080;
async getWeather() {
if (!this.station) this.station = WS1080.fromDevice();
return this.station.read();
}
onApplicationShutdown() {
this.station?.close();
}
}