From 2cd551f7c50c20ea2f941726737b7860ad85f1eb Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Sat, 16 Aug 2025 19:54:18 +0200 Subject: [PATCH] Fixes float being cast as int --- .env.dist => .env.example | 0 .gitignore | 1 + public/index.html | 2 +- source/main.ts | 6 +++--- 4 files changed, 5 insertions(+), 4 deletions(-) rename .env.dist => .env.example (100%) diff --git a/.env.dist b/.env.example similarity index 100% rename from .env.dist rename to .env.example diff --git a/.gitignore b/.gitignore index 57e85a4..c63973e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ node_modules/ dist/ +.env \ No newline at end of file diff --git a/public/index.html b/public/index.html index a3bb0c2..9213835 100644 --- a/public/index.html +++ b/public/index.html @@ -89,7 +89,7 @@ const data = await result.json(); TIMESTAMP_DISPLAY.textContent = new Date().toLocaleString(); - TEMP_DISPLAY.textContent = `${data.temperature.toLocaleString(undefined, { minimumFractionDigits: 2 })}°C`; + TEMP_DISPLAY.textContent = `${data.temperature.toLocaleString(undefined, { minimumFractionDigits: 1 })}°C`; MOISTURE.textContent = `${data.moisture}%`; } diff --git a/source/main.ts b/source/main.ts index 6a2209e..035a388 100644 --- a/source/main.ts +++ b/source/main.ts @@ -3,8 +3,8 @@ import dotenv from 'dotenv'; import * as fs from "node:fs"; import {Agent} from "undici"; -if (fs.existsSync(".env.dist")) { - dotenv.config({ path: '.env.dist'}); +if (fs.existsSync(".env")) { + dotenv.config({ path: '.env'}); } const URI = `${process.env.DOMAIN}/api/states`; @@ -25,7 +25,7 @@ async function getSensorValue(sensor: string): Promise { return -1; } const data: unknown = await result.json(); - return parseInt(data.state); + return parseFloat(data.state); } const server = express()