Skip to content

Commit

Permalink
Unit of measurement type defs (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoe authored Jul 13, 2024
1 parent c448023 commit 9b8b6d7
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ words:
- homekit
- hvac
- macaddress
- gbit
- cbar
- mbar
- quickboot
- rgbw
- rgbww
- rrule
- rtsp
- sonarjs
- mbit
- kbit
- ssdp
- systype
- tvshow
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@digital-alchemy/hass",
"repository": "https://github.com/Digital-Alchemy-TS/hass",
"homepage": "https://docs.digital-alchemy.app",
"version": "24.7.3",
"version": "24.7.4",
"scripts": {
"build": "rm -rf dist/; tsc",
"lint": "eslint src",
Expand Down Expand Up @@ -36,7 +36,7 @@
"license": "MIT",
"devDependencies": {
"@cspell/eslint-plugin": "^8.8.4",
"@digital-alchemy/core": "^24.6.6",
"@digital-alchemy/core": "^24.7.1",
"@digital-alchemy/synapse": "^24.6.6",
"@digital-alchemy/type-writer": "^24.6.6",
"@types/figlet": "^1.5.8",
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/entity-state.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TLabelId,
TRawDomains,
} from "../dynamic";
import { SensorUnitOfMeasurement } from "./registry";
import {
ALL_DOMAINS,
ALL_SERVICE_DOMAINS,
Expand Down Expand Up @@ -184,6 +185,7 @@ export interface Conversation {
export interface Sensor {
suggested_display_precision?: number;
display_precision?: null;
unit_of_measurement?: SensorUnitOfMeasurement;
}

export interface SensorPrivate {
Expand Down
109 changes: 109 additions & 0 deletions src/helpers/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,111 @@ export type ToggleExpose = {
should_expose: boolean;
};

export type SensorUnitOfMeasurement =
| "h"
| "min"
| "s"
| "d"
| "K"
| "°C"
| "°F"
| "cm"
| "in"
| "mm"
| "VA"
| "L"
| "gal"
| "m³"
| "ft³"
| "CCF"
| "kg"
| "g"
| "mg"
| "µg"
| "oz"
| "lb"
| "st"
| "ft/s"
| "km/h"
| "kn"
| "m/s"
| "mph"
| "in/d"
| "in/h"
| "mm/d"
| "V"
| "mV"
| "dB"
| "dBm"
| "mL"
| "fl. oz."
| "dBA"
| "cbar"
| "bar"
| "hPa"
| "inHg"
| "kPa"
| "mbar"
| "Pa"
| "psi"
| "var"
| "%"
| "None"
| "W"
| "kW"
| "µg/m³"
| "lx"
| "W/m²"
| "BTU/(h⋅ft²)"
| "Hz"
| "kHz"
| "MHz"
| "GHz"
| "Wh"
| "kWh"
| "MWh"
| "MJ"
| "GJ"
| "km"
| "m"
| "mi"
| "yd"
| "bit/s"
| "kbit/s"
| "Mbit/s"
| "Gbit/s"
| "B/s"
| "kB/s"
| "MB/s"
| "GB/s"
| "KiB/s"
| "MiB/s"
| "GiB/s"
| "bit"
| "kbit"
| "Mbit"
| "Gbit"
| "B"
| "kB"
| "MB"
| "GB"
| "TB"
| "PB"
| "EB"
| "ZB"
| "YB"
| "KiB"
| "MiB"
| "GiB"
| "TiB"
| "PiB"
| "EiB"
| "ZiB"
| "YiB"
| "A"
| "mA"
| "ppm";

export type EntityRegistryItem<ENTITY extends ANY_ENTITY> = {
area_id?: TAreaId;
categories: object;
Expand All @@ -56,6 +161,10 @@ export type EntityRegistryItem<ENTITY extends ANY_ENTITY> = {
conversation: {
should_expose?: boolean;
};
sensor?: {
display_precision?: number;
unit_of_measurement?: SensorUnitOfMeasurement;
};
};
original_name: string;
platform: TPlatformId;
Expand Down
25 changes: 23 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ __metadata:
languageName: node
linkType: hard

"@digital-alchemy/core@npm:^24.6.1, @digital-alchemy/core@npm:^24.6.6":
"@digital-alchemy/core@npm:^24.6.1":
version: 24.6.6
resolution: "@digital-alchemy/core@npm:24.6.6"
dependencies:
Expand All @@ -958,6 +958,27 @@ __metadata:
languageName: node
linkType: hard

"@digital-alchemy/core@npm:^24.7.1":
version: 24.7.1
resolution: "@digital-alchemy/core@npm:24.7.1"
dependencies:
chalk: "npm:^5.3.0"
dayjs: "npm:^1.11.11"
dotenv: "npm:^16.4.5"
ini: "npm:^4.1.3"
js-yaml: "npm:^4.1.0"
minimist: "npm:^1.2.8"
node-cache: "npm:^5.1.2"
node-cron: "npm:^3.0.3"
prom-client: "npm:^15.1.2"
redis: "npm:^4.6.14"
dependenciesMeta:
redis:
optional: true
checksum: 10/fd5dbdb47890c26348951a4ace7b4496b943d3271a2a50430a3456c2abf25de50192dd4e26e8d93279e040f13ba366f86d75686efadcc750d20dbaf1051189a6
languageName: node
linkType: hard

"@digital-alchemy/fastify-extension@npm:*":
version: 24.6.1
resolution: "@digital-alchemy/fastify-extension@npm:24.6.1"
Expand All @@ -978,7 +999,7 @@ __metadata:
resolution: "@digital-alchemy/hass@workspace:."
dependencies:
"@cspell/eslint-plugin": "npm:^8.8.4"
"@digital-alchemy/core": "npm:^24.6.6"
"@digital-alchemy/core": "npm:^24.7.1"
"@digital-alchemy/synapse": "npm:^24.6.6"
"@digital-alchemy/type-writer": "npm:^24.6.6"
"@types/figlet": "npm:^1.5.8"
Expand Down

0 comments on commit 9b8b6d7

Please sign in to comment.