import { IConnection } from "./connection" ; import { GW_PASSWORD_CHANGE_CFM } from "./KLF200-API/GW_PASSWORD_CHANGE_CFM" ; import { GW_PASSWORD_CHANGE_REQ } from "./KLF200-API/GW_PASSWORD_CHANGE_REQ" ; import { GW_COMMON_STATUS , GW_INVERSE_STATUS } from "./KLF200-API/common" ; import { SoftwareVersion , GW_GET_VERSION_CFM } from "./KLF200-API/GW_GET_VERSION_CFM" ; import { GW_GET_VERSION_REQ } from "./KLF200-API/GW_GET_VERSION_REQ" ; import { GW_GET_PROTOCOL_VERSION_CFM } from "./KLF200-API/GW_GET_PROTOCOL_VERSION_CFM" ; import { GW_GET_PROTOCOL_VERSION_REQ } from "./KLF200-API/GW_GET_PROTOCOL_VERSION_REQ" ; import { GatewayState , GatewaySubState , GW_GET_STATE_CFM } from "./KLF200-API/GW_GET_STATE_CFM" ; import { GW_GET_STATE_REQ } from "./KLF200-API/GW_GET_STATE_REQ" ; import { GW_SET_UTC_REQ } from "./KLF200-API/GW_SET_UTC_REQ" ; import { GW_RTC_SET_TIME_ZONE_CFM } from "./KLF200-API/GW_RTC_SET_TIME_ZONE_CFM" ; import { GW_RTC_SET_TIME_ZONE_REQ } from "./KLF200-API/GW_RTC_SET_TIME_ZONE_REQ" ; import { GW_REBOOT_REQ } from "./KLF200-API/GW_REBOOT_REQ" ; import { GW_SET_FACTORY_DEFAULT_REQ } from "./KLF200-API/GW_SET_FACTORY_DEFAULT_REQ" ; import { GW_LEAVE_LEARN_STATE_REQ } from "./KLF200-API/GW_LEAVE_LEARN_STATE_REQ" ; import { GW_GET_NETWORK_SETUP_REQ } from "./KLF200-API/GW_GET_NETWORK_SETUP_REQ" ; import { GW_GET_NETWORK_SETUP_CFM } from "./KLF200-API/GW_GET_NETWORK_SETUP_CFM" ; import { GW_SET_NETWORK_SETUP_REQ } from "./KLF200-API/GW_SET_NETWORK_SETUP_REQ" ; import { GW_HOUSE_STATUS_MONITOR_ENABLE_REQ } from "./KLF200-API/GW_HOUSE_STATUS_MONITOR_ENABLE_REQ" ; import { GW_HOUSE_STATUS_MONITOR_DISABLE_REQ } from "./KLF200-API/GW_HOUSE_STATUS_MONITOR_DISABLE_REQ" ; "use strict" ; export class export class Gateway { param { IConnection } connection memberof constructor ( readonly connection ) { } param { string } oldPassword param { string } newPassword returns { Promise < boolean > } memberof async changePasswordAsync ( oldPassword , newPassword ) { try { const passwordChanged = < GW_PASSWORD_CHANGE_CFM > await this . connection . sendFrameAsync ( new GW_PASSWORD_CHANGE_REQ ( oldPassword , newPassword ) ) ; return passwordChanged . Status === GW_COMMON_STATUS . SUCCESS ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < { SoftwareVersion : SoftwareVersion , HardwareVersion : number , ProductGroup : number , ProductType : number } > } memberof async getVersionAsync ( ) { try { const versionInformation = < GW_GET_VERSION_CFM > await this . connection . sendFrameAsync ( new GW_GET_VERSION_REQ ( ) ) ; return { SoftwareVersion : versionInformation . SoftwareVersion , HardwareVersion : versionInformation . HardwareVersion , ProductGroup : versionInformation . ProductGroup , ProductType : versionInformation . ProductType } ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < { MajorVersion : number , MinorVersion : number } > } memberof async getProtocolVersionAsync ( ) { try { const versionInformation = < GW_GET_PROTOCOL_VERSION_CFM > await this . connection . sendFrameAsync ( new GW_GET_PROTOCOL_VERSION_REQ ( ) ) ; return { MajorVersion : versionInformation . MajorVersion , MinorVersion : versionInformation . MinorVersion } ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < { GatewayState : GatewayState , SubState : GatewaySubState } > } memberof async getStateAsync ( ) { try { const state = < GW_GET_STATE_CFM > await this . connection . sendFrameAsync ( new GW_GET_STATE_REQ ( ) ) ; return { GatewayState : state . GatewayState , SubState : state . GatewaySubState } ; } catch ( error ) { return Promise . reject ( error ) ; } } param { Date } utcTimestamp returns { Promise < void > } memberof async setUTCDateTimeAsync ( utcTimestamp = new Date ( ) ) { try { await this . connection . sendFrameAsync ( new GW_SET_UTC_REQ ( utcTimestamp ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } param { string } timeZone returns { Promise < void > } memberof async setTimeZoneAsync ( timeZone ) { try { const timeZoneCFM = < GW_RTC_SET_TIME_ZONE_CFM > await this . connection . sendFrameAsync ( new GW_RTC_SET_TIME_ZONE_REQ ( timeZone ) ) ; if ( timeZoneCFM . Status !== GW_INVERSE_STATUS . SUCCESS ) throw new Error ( "Error setting time zone." ) ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < void > } memberof async rebootAsync ( ) { try { await this . connection . sendFrameAsync ( new GW_REBOOT_REQ ( ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < void > } memberof async factoryResetAsync ( ) { try { await this . connection . sendFrameAsync ( new GW_SET_FACTORY_DEFAULT_REQ ( ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < void > } memberof async leaveLearnStateAsync ( ) { try { await this . connection . sendFrameAsync ( new GW_LEAVE_LEARN_STATE_REQ ( ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < { IPAddress : string , Mask : string , DefaultGateway : string , DHCP : boolean } > } memberof async getNetworkSettingsAsync ( ) { try { const networkSettings = < GW_GET_NETWORK_SETUP_CFM > await this . connection . sendFrameAsync ( new GW_GET_NETWORK_SETUP_REQ ( ) ) ; return { IPAddress : networkSettings . IPAddress , Mask : networkSettings . Mask , DefaultGateway : networkSettings . DefaultGateway , DHCP : networkSettings . DHCP } ; } catch ( error ) { return Promise . reject ( error ) ; } } param { true } DHCP returns { Promise < void > } memberof async setNetworkSettingsAsync ( DHCP ) ; param { false } DHCP param { string } IPAddress param { string } Mask param { string } DefaultGateway returns { Promise < void > } memberof async setNetworkSettingsAsync ( DHCP , IPAddress , Mask , DefaultGateway ) ; async setNetworkSettingsAsync ( DHCP , IPAddress ? , Mask ? , DefaultGateway ? ) { try { if ( DHCP ) { IPAddress = Mask = DefaultGateway = "0.0.0.0" ; } await this . connection . sendFrameAsync ( new GW_SET_NETWORK_SETUP_REQ ( DHCP , IPAddress , Mask , DefaultGateway ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < void > } memberof async enableHouseStatusMonitorAsync ( ) { try { await this . connection . sendFrameAsync ( new GW_HOUSE_STATUS_MONITOR_ENABLE_REQ ( ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } returns { Promise < void > } memberof async disableHouseStatusMonitorAsync ( ) { try { await this . connection . sendFrameAsync ( new GW_HOUSE_STATUS_MONITOR_DISABLE_REQ ( ) ) ; } catch ( error ) { return Promise . reject ( error ) ; } } }