feat: add relay composables

This commit is contained in:
2026-05-14 22:41:11 +02:00
parent 03e53aa389
commit 970a38153e
9 changed files with 136 additions and 10 deletions

View File

@@ -0,0 +1,13 @@
import { isNil } from '../../utils/isNil';
import { RelayState, Relay, type RelayDto } from '../relay';
const relayStateToDomain = (dto: string | null): RelayState => {
if (isNil(dto) || dto.trim() === '') {
return RelayState.Off;
}
return dto.trim().toLowerCase() === 'on' ? RelayState.On : RelayState.Off;
};
export const relayDtoToDomain = (dto: RelayDto): Relay => {
return new Relay(dto.id, relayStateToDomain(dto.state), dto.label);
};

20
src/types/relay.ts Normal file
View File

@@ -0,0 +1,20 @@
import type { components } from '../api/schema';
export type RelayDto = components['schemas']['RelayDto'];
export enum RelayState {
On = 'on',
Off = 'off',
}
export class Relay {
id: number;
state: RelayState;
label: string;
constructor(id: number, state: RelayState, label: string) {
this.id = id;
this.state = state;
this.label = label;
}
}