0.0.3 • Published 9 months ago

vitrea-client v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Vitrea Client

Vitrea Smart Home API Client


Requirements

NodeJS version "^18.17.0 || >=20.5.0" is required to install this package.

Installation

npm install vitrea-client

Configurations

The section below outlines the different configuration values available and their corresponding default settings.

ConfigDescriptionDefault
VBoxConfigs.hostHost address to connect to the vBox192.168.1.23
VBoxConfigs.portPort used to connect to the vBox11501
VBoxConfigs.usernameUsername used to connect to the vBoxnull
VBoxConfigs.passwordPassword used to connect to the vBoxnull
VBoxConfigs.versionProtocol version of vBoxProtocolVersion.V2
SocketConfigs.logLogger to print valuesnull
SocketConfigs.shouldReconnectAutomatically reconnect on lost connectiontrue
SocketConfigs.socketSupplierProvide a prebuilt Net.Socket objectnull
SocketConfigs.requestTimeoutMax timeout for requests1000

Environment Variables

If you prefer not to provide the configuration values directly, you can use environment variables instead.

All VBoxConfigs configuration values can be represented as environment variables by converting the config key to uppercase and prefixing it with VITREA_VBOX_. For instance, the key username would be represented as VITREA_VBOX_USERNAME.

Usage

import {
    ProtocolVersion,
    Requests,
    VitreaClient
} from 'vitrea-client'


const client = VitreaClient.create({
    host:     '192.168.1.111',
    port:     1234,
    username: 'admin',
    password: 'secret',
    version:  ProtocolVersion.V1
})

await client.connect()

const count = await client.send(new Requests.RoomCount())

Logging

By default, all logs are sent to the NullLogger, which discards them. To log messages, you can use our ConsoleLogger (which wraps the native console object), set below:

import { ConsoleLogger, VitreaClient } from 'vitrea-client'

const client = VitreaClient.create(
    { /* ... */ },
    {
        log: new ConsoleLogger()
    }
)

If you already have a logger that implements the interface below, you can integrate it as follows:

import { getLogger }    from '@/core/logger'
import { VitreaClient } from 'vitrea-client'

const client = VitreaClient.create(
    { /* ... */ },
    {
        log: getLogger('vBox')
    }
)
interface LoggerContract<T = any, R = void> {
    log(message: string, level: string): R
    error(message: string, ...args: T[]): R
    warn(message: string, ...args: T[]): R
    info(message: string, ...args: T[]): R
    debug(message: string, ...args: T[]): R
}

Status Updates

Vitrea's vBox sends updates to the client whenever a key is pressed. You can supply a custom callback listener to manage these updates as they happen.

import { VitreaClient, Responses } from 'vitrea-client'

const client = VitreaClient.create(...)

const listener = (status: Responses.KeyStatus) => {
    console.log(status.nodeID)
    console.log(status.keyID)
    console.log(status.isOff)
    console.log(status.isOn)
}

client.onKeyStatus(listener)
0.0.1

10 months ago

0.0.3

9 months ago

0.0.2

10 months ago

0.0.1-alpha.2

10 months ago

0.0.1-alpha.3

10 months ago

0.0.1-rc.1

10 months ago

0.0.1-rc.2

10 months ago

0.0.1-beta.1

10 months ago

0.0.1-alpha.1

11 months ago