mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 08:12:52 +00:00
feat(measurements): accept indoor CO2, temperature and humidity
Room climate from a home automation system gets three types of its own: INDOOR_CO2 (ppm), INDOOR_TEMPERATURE (celsius, shown in Fahrenheit for imperial readers) and INDOOR_HUMIDITY (percent). They arrive through the existing ingest token (measurements:write, source EXTERNAL), sit in the environment cluster beside daylight, and the daily rollup carries their mean, low and high like any spot reading. They never mix with the body temperatures or with the outdoor environment channels. The Home Assistant page documents the three types, a rest_command that sends a room as one request, a single-room automation, and an importable blueprint (docs/integrations/blueprints) that skips sensors reporting unknown or non-numeric states, converts Fahrenheit, and stamps readings to the minute so a retried push is refused rather than written twice.
This commit is contained in:
1 parent
b76826a5f8
commit
cc8ea3dfbb
32 files changed
+463
-9
No files matched your search
@@ -23,6 +23,10 @@ import type { MeasurementType } from "@/generated/prisma/client";
|
||||
* silently failing the assertion.
|
||||
*/
|
||||
const MEASUREMENT_TYPES_WITHOUT_HK_COUNTERPART = new Set<MeasurementType>([
|
||||
// v1.44 — room climate arrives through the ingest token, not HealthKit.
|
||||
"INDOOR_CO2",
|
||||
"INDOOR_TEMPERATURE",
|
||||
"INDOOR_HUMIDITY",
|
||||
// Withings-only metrics (no HK identifier ships any of these as a
|
||||
// first-class quantity — Apple delegates body-composition tail to
|
||||
// third-party devices via the BodyMass/BodyFat pair).
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { getUnitForType } from "@/lib/measurements/unit-map";
|
||||
import { getDisplayTransform } from "@/lib/measurements/display-transform";
|
||||
import { getMeasurementCategory } from "@/lib/measurements/categories";
|
||||
import { createMeasurementSchema } from "@/lib/validations/measurement";
|
||||
|
||||
/**
|
||||
* Room climate as a Home Assistant automation pushes it: the documented
|
||||
* three-reading array through the ingest token, no source, no unit.
|
||||
*/
|
||||
const at = new Date(Date.now() - 60_000).toISOString();
|
||||
|
||||
describe("indoor climate types", () => {
|
||||
it("accepts the documented push shape for all three", () => {
|
||||
for (const [type, value] of [
|
||||
["INDOOR_CO2", 812],
|
||||
["INDOOR_TEMPERATURE", 21.4],
|
||||
["INDOOR_HUMIDITY", 47],
|
||||
] as const) {
|
||||
expect(
|
||||
createMeasurementSchema.safeParse({ type, value, measuredAt: at })
|
||||
.success,
|
||||
type,
|
||||
).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("refuses a reading no room produces", () => {
|
||||
for (const [type, value] of [
|
||||
["INDOOR_CO2", 12_000],
|
||||
["INDOOR_TEMPERATURE", 75],
|
||||
["INDOOR_HUMIDITY", 101],
|
||||
] as const) {
|
||||
expect(
|
||||
createMeasurementSchema.safeParse({ type, value, measuredAt: at })
|
||||
.success,
|
||||
type,
|
||||
).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("stores canonical units and shows temperature in the person's scale", () => {
|
||||
expect(getUnitForType("INDOOR_CO2")).toBe("ppm");
|
||||
expect(getUnitForType("INDOOR_TEMPERATURE")).toBe("celsius");
|
||||
expect(getUnitForType("INDOOR_HUMIDITY")).toBe("%");
|
||||
expect(
|
||||
getDisplayTransform("INDOOR_TEMPERATURE", "imperial").displayUnit,
|
||||
).toBe("°F");
|
||||
});
|
||||
|
||||
it("files all three under the environment cluster", () => {
|
||||
for (const type of [
|
||||
"INDOOR_CO2",
|
||||
"INDOOR_TEMPERATURE",
|
||||
"INDOOR_HUMIDITY",
|
||||
] as const) {
|
||||
expect(getMeasurementCategory(type)).toBe("environment");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -67,6 +67,7 @@ const SHARED_SYMBOLS: ReadonlySet<string> = new Set([
|
||||
"°C",
|
||||
"°F",
|
||||
"dBA",
|
||||
"ppm",
|
||||
"mL/(kg·min)",
|
||||
"kg/m²",
|
||||
"mL",
|
||||
|
||||
@@ -230,6 +230,10 @@ export const MEASUREMENT_CATEGORIES: ReadonlyMap<
|
||||
["STATE_OF_MIND_VALENCE", "scores"],
|
||||
// AFib burden joins the rhythm notifications on the cardiovascular surface.
|
||||
["AFIB_BURDEN", "cardiovascular"],
|
||||
// ── v1.44 — room climate joins daylight in the environment cluster ──
|
||||
["INDOOR_CO2", "environment"],
|
||||
["INDOOR_TEMPERATURE", "environment"],
|
||||
["INDOOR_HUMIDITY", "environment"],
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -179,6 +179,8 @@ const TRANSFORMS: Partial<
|
||||
BODY_TEMPERATURE: TEMPERATURE_TRANSFORM,
|
||||
SKIN_TEMPERATURE: TEMPERATURE_TRANSFORM,
|
||||
WRIST_TEMPERATURE: TEMPERATURE_TRANSFORM,
|
||||
// v1.44 — room temperature reads in the person's own scale too.
|
||||
INDOOR_TEMPERATURE: TEMPERATURE_TRANSFORM,
|
||||
// A signed baseline DEVIATION (Δ°C) — the °F imperial branch scales by
|
||||
// 1.8 but carries NO +32 offset. A one-degree-Celsius deviation is a
|
||||
// 1.8-degree-Fahrenheit deviation, not a 33.8 °F reading.
|
||||
@@ -338,6 +340,8 @@ const INTEGER_DISPLAY_TYPES: ReadonlySet<string> = new Set([
|
||||
"STAND_MINUTES",
|
||||
"STAND_HOURS",
|
||||
"MINDFUL_MINUTES",
|
||||
// CO2 sensors report whole ppm.
|
||||
"INDOOR_CO2",
|
||||
]);
|
||||
|
||||
/**
|
||||
|
||||
@@ -110,6 +110,9 @@ export const MEASUREMENT_TYPE_LABEL_KEYS: Record<MeasurementType, string> = {
|
||||
MINDFUL_MINUTES: "measurements.typeMindfulMinutes",
|
||||
STATE_OF_MIND_VALENCE: "measurements.typeStateOfMindValence",
|
||||
AFIB_BURDEN: "measurements.typeAfibBurden",
|
||||
INDOOR_CO2: "measurements.typeIndoorCo2",
|
||||
INDOOR_TEMPERATURE: "measurements.typeIndoorTemperature",
|
||||
INDOOR_HUMIDITY: "measurements.typeIndoorHumidity",
|
||||
GRIP_STRENGTH: "measurements.typeGripStrength",
|
||||
PAIN_NRS: "measurements.typePainNrs",
|
||||
WAIST_CIRCUMFERENCE: "measurements.typeWaistCircumference",
|
||||
|
||||
@@ -166,6 +166,10 @@ const unitMap: Record<string, string> = {
|
||||
STATE_OF_MIND_VALENCE: "valence",
|
||||
// Percent of the week after the ×100 scaling.
|
||||
AFIB_BURDEN: "%",
|
||||
// ── v1.44 — room climate ──
|
||||
INDOOR_CO2: "ppm",
|
||||
INDOOR_TEMPERATURE: "celsius",
|
||||
INDOOR_HUMIDITY: "%",
|
||||
};
|
||||
|
||||
export function getUnitForType(type: string): string {
|
||||
|
||||
Reference in new issue
Block a user