1-
2- import { IClientOptions } from 'mqtt' ;
3- import { ISpecificationTexts , IbaseSpecification , IdentifiedStates , IimageAndDocumentUrl , ImodbusEntityIdentification , SpecificationStatus } from '@modbus2mqtt/specification.shared' ;
1+ import { IClientOptions } from 'mqtt'
2+ import {
3+ ISpecificationTexts ,
4+ IbaseSpecification ,
5+ IdentifiedStates ,
6+ IimageAndDocumentUrl ,
7+ ImodbusEntityIdentification ,
8+ SpecificationStatus ,
9+ } from '@modbus2mqtt/specification.shared'
410
511export enum HttpErrorsEnum {
6- OK = 200 ,
7- OkCreated = 201 ,
8- OkAccepted = 202 ,
9- OkNonAuthoritativeInformation = 203 ,
10- OkNoContent = 204 ,
11- ErrBadRequest = 400 ,
12- ErrUnauthorized = 401 ,
13- ErrForbidden = 403 ,
14- ErrNotFound = 404 ,
15- ErrNotAcceptable = 406 ,
16- ErrRequestTimeout = 408 ,
17- ErrInvalidParameter = 422 ,
18- SrvErrInternalServerError = 500
12+ OK = 200 ,
13+ OkCreated = 201 ,
14+ OkAccepted = 202 ,
15+ OkNonAuthoritativeInformation = 203 ,
16+ OkNoContent = 204 ,
17+ ErrBadRequest = 400 ,
18+ ErrUnauthorized = 401 ,
19+ ErrForbidden = 403 ,
20+ ErrNotFound = 404 ,
21+ ErrNotAcceptable = 406 ,
22+ ErrRequestTimeout = 408 ,
23+ ErrInvalidParameter = 422 ,
24+ SrvErrInternalServerError = 500 ,
1925}
2026export enum RoutingNames {
21- login = 'login' ,
22- register = 'register' ,
23- configure = 'configure' ,
24- busses = 'busses' ,
25- specifications = 'specifications' ,
26- slaves = 'slaves' ,
27- specification = 'specification'
27+ login = 'login' ,
28+ register = 'register' ,
29+ configure = 'configure' ,
30+ busses = 'busses' ,
31+ specifications = 'specifications' ,
32+ slaves = 'slaves' ,
33+ specification = 'specification' ,
2834}
2935export interface ImqttClient extends IClientOptions {
30- mqttserverurl ?: string ,
31- ssl ?: boolean
36+ mqttserverurl ?: string
37+ ssl ?: boolean
3238}
3339
3440export interface IRTUConnection {
35- serialport : string ,
36- baudrate : number ,
37- timeout : number
41+ serialport : string
42+ baudrate : number
43+ timeout : number
3844}
3945export interface ITCPConnection {
40- host : string ,
41- port : number ,
42- timeout : number
46+ host : string
47+ port : number
48+ timeout : number
4349}
4450
45- export type IModbusConnection = ( IRTUConnection | ITCPConnection ) ;
51+ export type IModbusConnection = IRTUConnection | ITCPConnection
4652
4753export interface Iconfiguration {
48- hassiotoken ?: string ;
49- password ?: string ;
50- username ?: string ;
51- githubPersonalToken ?: string ;
52- version : string ,
53- fakeModbus : boolean ;
54- mqttbasetopic : string ;
55- mqttdiscoveryprefix : string ;
56- mqttdiscoverylanguage : string ;
57- mqttusehassiotoken ?: boolean ;
58- mqttconnect : ImqttClient ;
59- mqttcaFile ?: string ;
60- mqttkeyFile ?: string ;
61- mqttcertFile ?: string ;
62- filelocation : string ;
63- httpport : number ;
64- rootUrl ?: string ;
54+ hassiotoken ?: string
55+ password ?: string
56+ username ?: string
57+ githubPersonalToken ?: string
58+ version : string
59+ fakeModbus : boolean
60+ mqttbasetopic : string
61+ mqttdiscoveryprefix : string
62+ mqttdiscoverylanguage : string
63+ mqttusehassiotoken ?: boolean
64+ mqttconnect : ImqttClient
65+ mqttcaFile ?: string
66+ mqttkeyFile ?: string
67+ mqttcertFile ?: string
68+ filelocation : string
69+ httpport : number
70+ rootUrl ?: string
6571}
6672export enum AuthenticationErrors {
67- EnvironmentVariableSecretNotSet = 1 ,
68- HashError = 2 ,
69- InvalidUserPasswordCombination = 3 ,
70- InvalidParameters = 4 ,
71- SignError = 5
73+ EnvironmentVariableSecretNotSet = 1 ,
74+ HashError = 2 ,
75+ InvalidUserPasswordCombination = 3 ,
76+ InvalidParameters = 4 ,
77+ SignError = 5 ,
7278}
7379
7480export interface IUserAuthenticationStatus {
75- registered : boolean ,
76- hassiotoken : boolean ,
77- hasAuthToken : boolean ,
78- authTokenExpired : boolean ,
79- mqttConfigured : boolean ,
80- preSelectedBusId ?: number
81+ registered : boolean
82+ hassiotoken : boolean
83+ hasAuthToken : boolean
84+ authTokenExpired : boolean
85+ mqttConfigured : boolean
86+ preSelectedBusId ?: number
8187}
8288export interface IBus {
83- busId : number ,
84- connectionData : IModbusConnection ,
85- slaves : Islave [ ]
89+ busId : number
90+ connectionData : IModbusConnection
91+ slaves : Islave [ ]
8692}
8793export function getConnectionName ( connection : IModbusConnection ) : string {
88- if ( ( connection as IRTUConnection ) . baudrate ) {
89- let c = ( connection as IRTUConnection ) ;
90- return "RTU: " + c . serialport + "(" + c . baudrate + ") t: " + c . timeout ;
91- }
92- else {
93- let c = ( connection as ITCPConnection ) ;
94- return "TCP: " + c . host + ":" + c . port + " t: " + ( c . timeout ? c . timeout : 100 ) ;
95- }
94+ if ( ( connection as IRTUConnection ) . baudrate ) {
95+ let c = connection as IRTUConnection
96+ return 'RTU: ' + c . serialport + '(' + c . baudrate + ') t: ' + c . timeout
97+ } else {
98+ let c = connection as ITCPConnection
99+ return 'TCP: ' + c . host + ':' + c . port + ' t: ' + ( c . timeout ? c . timeout : 100 )
100+ }
96101}
97102
98103export interface Islave {
99- slaveid : number ;
100- specificationid ?: string ;
101- name ?: string ;
102- polInterval ?: number ;
103- specification ?: IbaseSpecification ;
104- durationOfLongestModbusCall ?: number ;
105- modbusTimout ?: number ;
106- evalTimeout ?: boolean ;
107- detectSpec ?: boolean ; // Will be set when creating a slave. If true, modbus2mqtt will set a specification matching to the modbusdata if there is one
104+ slaveid : number
105+ specificationid ?: string
106+ name ?: string
107+ polInterval ?: number
108+ specification ?: IbaseSpecification
109+ durationOfLongestModbusCall ?: number
110+ modbusTimout ?: number
111+ evalTimeout ?: boolean
112+ detectSpec ?: boolean // Will be set when creating a slave. If true, modbus2mqtt will set a specification matching to the modbusdata if there is one
108113}
109114
110115export interface IidentificationSpecification {
111- filename : string ;
112- status : SpecificationStatus ;
113- entities : ImodbusEntityIdentification [ ] ;
114- files : IimageAndDocumentUrl [ ] ;
115- i18n : ISpecificationTexts [ ] ;
116- identified : IdentifiedStates ;
117- configuredSlave ?: Islave ;
118- }
116+ filename : string
117+ status : SpecificationStatus
118+ entities : ImodbusEntityIdentification [ ]
119+ files : IimageAndDocumentUrl [ ]
120+ i18n : ISpecificationTexts [ ]
121+ identified : IdentifiedStates
122+ configuredSlave ?: Islave
123+ }
0 commit comments