Compare commits
5 Commits
v1.8.4
...
c1c5a41aa5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1c5a41aa5 | ||
|
|
2b85020d52 | ||
|
|
493739238e | ||
|
|
7d96b3a82e | ||
|
|
f49c868007 |
2
dist/fastify.js
vendored
2
dist/fastify.js
vendored
@@ -1,4 +1,4 @@
|
|||||||
import { logWarning } from "./logger";
|
import { logWarning } from "./logger.js";
|
||||||
export class API_Error {
|
export class API_Error {
|
||||||
error;
|
error;
|
||||||
constructor(error) {
|
constructor(error) {
|
||||||
|
|||||||
2
dist/homeassistant.d.ts
vendored
2
dist/homeassistant.d.ts
vendored
@@ -21,11 +21,9 @@ export type HomeAssistantEntity = {
|
|||||||
export interface HomeAssistantDeskPositionResult {
|
export interface HomeAssistantDeskPositionResult {
|
||||||
raw: HomeAssistantEntity;
|
raw: HomeAssistantEntity;
|
||||||
as_boolean: boolean;
|
as_boolean: boolean;
|
||||||
as_text: () => string;
|
|
||||||
last_changed: TimeBetween;
|
last_changed: TimeBetween;
|
||||||
}
|
}
|
||||||
export type API_HA_DeskPosition = {
|
export type API_HA_DeskPosition = {
|
||||||
position: string;
|
|
||||||
is_standing: boolean;
|
is_standing: boolean;
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
last_changed_seconds: number;
|
last_changed_seconds: number;
|
||||||
|
|||||||
2
dist/homeassistant.d.ts.map
vendored
2
dist/homeassistant.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACX,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC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O,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CACF,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC"}
|
||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.8.4",
|
"version": "1.9.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.8.4",
|
"version": "1.9.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/ws": "^8.18.1",
|
"@types/ws": "^8.18.1",
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.8.4",
|
"version": "1.9.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { AxiosInstance } from "axios";
|
import type { AxiosInstance } from "axios";
|
||||||
import { logWarning } from "./logger";
|
import { logWarning } from "./logger.js";
|
||||||
|
|
||||||
export type ServiceResult<T = unknown> = {
|
export type ServiceResult<T = unknown> = {
|
||||||
result: T;
|
result: T;
|
||||||
|
|||||||
@@ -23,12 +23,10 @@ export type HomeAssistantEntity = {
|
|||||||
export interface HomeAssistantDeskPositionResult {
|
export interface HomeAssistantDeskPositionResult {
|
||||||
raw: HomeAssistantEntity;
|
raw: HomeAssistantEntity;
|
||||||
as_boolean: boolean;
|
as_boolean: boolean;
|
||||||
as_text: () => string;
|
|
||||||
last_changed: TimeBetween;
|
last_changed: TimeBetween;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type API_HA_DeskPosition = {
|
export type API_HA_DeskPosition = {
|
||||||
position: string;
|
|
||||||
is_standing: boolean;
|
is_standing: boolean;
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
last_changed_seconds: number;
|
last_changed_seconds: number;
|
||||||
|
|||||||
@@ -51,30 +51,36 @@ export function calculateSecondsBetween(
|
|||||||
return {
|
return {
|
||||||
seconds,
|
seconds,
|
||||||
toReadable: (roundToMinutes?: boolean) =>
|
toReadable: (roundToMinutes?: boolean) =>
|
||||||
secondsToReadable(seconds, roundToMinutes),
|
formatSecondsToDHMS(seconds, roundToMinutes),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function secondsToReadable(
|
export function formatSecondsToDHMS(
|
||||||
secs: number,
|
secs: number,
|
||||||
roundToMinutes: boolean = false,
|
roundToMinutes: boolean = false,
|
||||||
): string {
|
): string {
|
||||||
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
|
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
|
||||||
|
|
||||||
var days = Math.floor(totalSeconds / (3600 * 24));
|
const days = Math.floor(totalSeconds / (3600 * 24));
|
||||||
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
const hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
||||||
var minutes = Math.floor((totalSeconds % 3600) / 60);
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
var seconds = Math.floor(totalSeconds % 60);
|
const seconds = Math.floor(totalSeconds % 60);
|
||||||
|
|
||||||
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
const dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
||||||
var hourDisplay =
|
const hourDisplay =
|
||||||
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
||||||
var minuteDisplay =
|
const minuteDisplay =
|
||||||
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
||||||
var secondDisplay =
|
const secondDisplay =
|
||||||
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
||||||
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
|
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
|
||||||
/,\s*$/,
|
/,\s*$/,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatSecondsToMS(s: number): string {
|
||||||
|
const mins = Math.floor(s / 60);
|
||||||
|
const secs = s % 60;
|
||||||
|
return `${mins}:${secs < 10 ? "0" : ""}${secs}`;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user