UNPKG

lavva.exalushome

Version:

Library implementing communication and abstraction layers for ExalusHome system

300 lines (299 loc) 13.7 kB
import { Status } from "../../DataFrame"; import { IntRange } from "../../Helpers"; import { IDevice } from "../Devices/IDevice"; import { ResponseResult } from "../FieldChangeResult"; import { ICustomUpdateActions } from "./CustomUpdateActions/ICustomUpdateActions"; import { ControllerUpdatesInfo, ControllerVersion, DeviceUpdateShortInfo, IDeviceUpdateInfo, UpdateHistory } from "./IUpdateInfo"; export interface IUpdatesService { GetServiceName(): string; IsBranchAndAutomaticUpdatesSettingSupportedAsync(): Promise<boolean>; /** * Checks available controller updates */ CheckControllerUpdatesAsync(): Promise<ControllerUpdatesInfo>; /** * Checks if controller software update is available */ CheckControllerSoftwareUpdateAvailabilityAsync(): Promise<boolean>; /** * Checks if device firmware update is available, update is check in background by controller every night */ CheckDevicesUpdatesAvailabilityAsync(): Promise<DeviceUpdateShortInfo[]>; /** * Checks available device update * @param deviceGuid */ CheckDeviceUpdateAsync(deviceGuid: string): Promise<IDeviceUpdateInfo | ResponseResult<UpdateErrorCode>>; /** * Checks available device update * @param device */ CheckDeviceUpdateAsync(device: IDevice): Promise<IDeviceUpdateInfo | ResponseResult<UpdateErrorCode>>; /** * Checks available updates for all devices * @param reloadCache updates are automatically checked every night, but if you want to force update check, set this parameter to true, it will increase the time of response! */ CheckDeviceUpdatesBulkAsync(reloadCache?: boolean): Promise<IDeviceUpdateInfo[] | ResponseResult<UpdateErrorCode>>; /** * Method to get current update branch of controller software (default: public) */ GetControllerUpdateBranchAsync(): Promise<UpdateBranch | ResponseResult<UpdateErrorCode>>; /** * Method to set update branch of controller software * @param updateBranch update branch, for users should be available: public, beta */ SetControllerUpdateBranchAsync(updateBranch: UpdateBranch): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; DownloadControllerUpdateAsync<T extends ICustomUpdateActions>(downloadProgress: DownloadProgress): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Function to install single controller update, before use this function we need to use CheckControllerUpdatesAsync() to check if any updates are available. * @param updateProgress callback function which is called when recived information about update progress from controller * @param downloadProgress (only for controller software update) callback function which is called when recived information about download progress from controller * @param updateGuid update guid - present in ControllerUpdatesInfo object * @param downloadOnly (only for controller software update) if true, the update will be downloaded but not installed, after download finished you need to call again CheckControllerUpdatesAsync and pass correct updateGuid to install downloaded update. * @param updateAction custom actions to do (may be protocol-dependent or may not occur) * @returns Status.OK when update is finished (regardless of UpdateProgress result, the update result is given in the callback) */ InstallControllerOrRadioUpdateAsync<T extends ICustomUpdateActions>(updateProgress: UpdateProgress, downloadProgress: DownloadProgress, updateGuid: string): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Function to install all controller updates, before use this function we need to use CheckControllerUpdatesAsync() to check if any updates are available. * @param updateProgress callback function which is called when recived information about update progress from controller * @param downloadProgress (only for controller software update) callback function which is called when recived information about download progress from controller * @param updateAction custom actions to do (may be protocol-dependent or may not occur) * @returns Status.OK when update is finished (regardless of UpdateProgress result, the update result is given in the callback) */ InstallControllerOrRadioUpdateAsync<T extends ICustomUpdateActions>(updateProgress: UpdateProgress, downloadProgress: DownloadProgress): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Function to enable automatic updates downloading. Automatic downloading is preformed at night by controller when updates are available. * * Automatic download is enabled by default. */ EnableAutomaticControllerUpdateDownloadAsync(): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Function to disable automatic updates downloading at night (enabled by default). */ DisableAutomaticControllerUpdateDownloadAsync(): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Function to get status of automatic updates downloading. * @returns true if automatic updates downloading is enabled, false if not */ GetAutomaticControllerUpdateDownloadStatusAsync(): Promise<boolean | ResponseResult<UpdateErrorCode>>; /** * Function to get history of controller updates */ GetControllerUpdatesHistoryAsync(): Promise<UpdateHistory[] | ResponseResult<UpdateErrorCode>>; /** * Installs a device update if available * @param device IDevice object * @param updateProgress callback function which is called when recived information about update progress from controller * @param updateAction custom actions to do (may be protocol-dependent or may not occur) * @param force force update installation (if retransmitter warning error occur) * @returns Status.OK when update is finished (regardless of UpdateProgress result, the update result is given in the callback) * When any update is not finished with success, method returns UpdatesPartiallyInstalled error code. */ InstallDeviceUpdateAsync<T extends ICustomUpdateActions>(device: IDevice, updateProgress: UpdateProgress, updateAction?: UpdateAction<T>, force?: boolean): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Installs a device update if available * @param deviceGuid device Guid * @param updateProgress callback function which is called when recived information about update progress from controller * @param updateAction custom actions to do (may be protocol-dependent or may not occur) * @param force force update installation (if retransmitter warning error occur) * @returns Status.OK when update is finished (regardless of UpdateProgress result, the update result is given in the callback) */ InstallDeviceUpdateAsync<T extends ICustomUpdateActions>(deviceGuid: string, updateProgress: UpdateProgress, updateAction?: UpdateAction<T>, force?: boolean): Promise<Status.OK | ResponseResult<UpdateErrorCode>>; /** * Installs updates for all devices if available, update avabality for devices coud be confirmed by CheckDeviceUpdatesBulkAsync() * @param deviceGuids guids of devices that should be updated * @param updateProgress callback function which is called when recived information about update progress from controller * @param updateAction custom actions to do (may be protocol-dependent or may not occur) * @returns */ InstallDevicesUpdateBulkAsync<T extends ICustomUpdateActions>(deviceGuids: string[], updateProgress: UpdateProgress, updateAction?: UpdateAction<T>): Promise<BulkUpdateResult | ResponseResult<UpdateErrorCode>>; /** * The function checks the version of all components available on the controller (radio, software, etc.). */ CheckControllerVersionAsync(): Promise<ControllerVersion[] | ResponseResult<UpdateErrorCode>>; /** * Function returns current software version. * @param deviceGuid */ CheckDeviceVersionAsync(deviceGuid: string): Promise<string | ResponseResult<UpdateErrorCode>>; /** * Function returns current software versions (radio, software, etc.). * @param device */ CheckDeviceVersionAsync(device: IDevice): Promise<string | ResponseResult<UpdateErrorCode>>; /** * Returns currently pending installation progress of controller software update. */ CheckControllerPendingUpdateProgressAsync(updateProgress: UpdateProgress, downloadProgess: DownloadProgress): Promise<ResponseResult<UpdateErrorCode> | Status.OK>; /** * Cancels currently pending installation of controller software update. * @returns Status.OK when cancel is successful, Status.Error when cancel failed, Status.OperationNotPermitted when no update is pending */ CancelFailedControllerUpdateAsync(): Promise<Status.OK | Status.Error | Status.OperationNotPermitted>; /** * Tells us if it is possible to cancel currently pending installation of controller software update or get pending update progress. */ CanCancelFailedControllerUpdateOrGetPendingUpdateProgress(): boolean; } export type UpdateProgress = (updateProgress: UpdateProgressInfo) => void; export type DownloadProgress = (downloadProgress: DownloadProgressInfo) => void; export type UpdateAction<T extends ICustomUpdateActions> = (updateAction: T) => any; export type Progress = IntRange<0, 101>; export declare enum UpdateStatus { DownloadingFailure = -5, InstallationStopped = -4, InstallationError = -3, IncompatiblePackage = -2, Error = -1, OK = 0, DownloadingPackage = 1, CheckingPackage = 2, PreparingForUpgrade = 3, Upgrading = 4, MovingData = 5, Reloading = 6, Upgraded = 7 } export declare enum UpdateState { WaitingForUser = 1, Downloading = 2, Unpackaging = 3, CheckingApplicability = 4, MigratingData = 5, CreatingBackup = 6, Deploying = 7, Installing = 8, Removing = 9, Error = 10, ReadyToDownload = 11, PreparingSystem = 12, CheckingPackageIntegrity = 13, CheckingIntegrity = 14, UndoingInstallation = 15, Installed = 16 } export declare enum UserInput { Ignore = 0, Cancel = 1, Install = 2 } export declare class UpdateProgressInfo { /** * Map of resource names * * As key we have language code as specified in RFC 4646. As value we have description of update in specified language. * https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-7.0 * https://www.ietf.org/rfc/rfc4646.txt * ex. pl-PL, en-US */ UpdatedResourceName: Map<string, string>; /** * Percentage of installation progress */ Percentage: Progress; /** * Percentage of total update progress */ PercentageTotal: Progress; /** * Current state of update */ Status: UpdateStatus; /** * Number of current installing update */ UpdateNumber: number; /** * Number of all updates to install */ AvailableUpdates: number; } export declare class DownloadProgressInfo { /** * Map of resource names * * As key we have language code as specified in RFC 4646. As value we have description of update in specified language. * https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization?view=aspnetcore-7.0 * https://www.ietf.org/rfc/rfc4646.txt * ex. pl-PL, en-US */ UpdatedResourceName: Map<string, string>; /** * Percentage of download progress */ Percentage: Progress; /** * Percentage of total update progress */ PercentageTotal: Progress; /** * Speed of download in Megabits per second */ SpeedMbps: number; CurrentTask: DownloadTask; DownloadOnly: boolean; } export declare class BulkUpdateResult { /** * General status of bulk update */ BulkUpdateStatus: BulkUpdateStatus; /** * Map of device update results, as key we have device guid */ DevicesUpdateResults: Map<string, BulkUpdateDeviceStatus>; } export declare enum BulkUpdateStatus { Success = 0, PartialSuccess = 1, UpdatesNotFound = 2, CannotUnpairRetransmitters = 3, CannotPairRetransmitters = 4 } export declare enum BulkUpdateDeviceStatus { Unknown = 0, Updated = 1, InsufficientConnection = 2, Error = 3, UnknownError = 4, ControllerSoftwareTooOld = 5 } export declare enum DownloadTask { Unknown = 0, DownloadingUpdate = 1, DownloadingInstaller = 2, CheckingUpdate = 3, UpdateDownloadedAndChecked = 4 } export declare enum UpdateErrorCode { DeviceIsUpToDate = 0, CannotFindDevice = 1, UnsupportedApiVersion = 2, UnsupportedDevice = 3, CannotGetFirmwareVersion = 4, CannotGetUpdates = 5, CannotProcessUpdate = 6, UpdateActionsNotSupported = 7, UnsupportedExtensionVersion = 8, UpdatesPartiallyInstalled = 9, RetransmitterFound = 10, ProtocolRadioUnsupported = 11, FeatureUnsupportedInCurrentVersion = 12, CannotGetUpdatesBranch = 13, CannotSetUpdatesBranch = 14, UpdateAlreadyDownloaded = 15, UpdateDownloadFailed = 16, UpdateAlreadyInstalled = 17, CannotGetCurrentControllerVersionTimeout = 18, CannotGetCurrentControllerVersion = 19, InstallerFileSignCheckFailed = 20, UpdateFileSignCheckFailed = 21, UpdateFileCheckFailed = 22, UpdateInstallationFailed = 23 } export declare enum UpdateBranch { Public = "public", Beta = "beta", Development = "dev" }