unifi-access
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import { RequestOptions, Response } from "@adobe/fetch"; | ||
@@ -18,4 +17,4 @@ import { AccessBootstrapConfig, AccessControllerConfig, AccessDeviceConfig, AccessDeviceConfigPayload, AccessDoorConfig, AccessFloorConfig } from "./access-types.js"; | ||
* | ||
* 3. Listen for `message` events emitted by {@link AccessApi} containing all Access controller events, in realtime. They are delivered as {@link AccessEventPacket} | ||
* packets, containing the event-specific details. | ||
* 3. Listen for `message` events emitted by {@link AccessApi} containing all Access controller events, in realtime. They are delivered as | ||
* {@link access-types.AccessEventPacket} packets, containing the event-specific details. | ||
* | ||
@@ -22,0 +21,0 @@ * Those are the basics that gets us up and running. |
@@ -22,4 +22,4 @@ /* Copyright(C) 2019-2024, HJD (https://github.com/hjdhjd). All rights reserved. | ||
* | ||
* 3. Listen for `message` events emitted by {@link AccessApi} containing all Access controller events, in realtime. They are delivered as {@link AccessEventPacket} | ||
* packets, containing the event-specific details. | ||
* 3. Listen for `message` events emitted by {@link AccessApi} containing all Access controller events, in realtime. They are delivered as | ||
* {@link access-types.AccessEventPacket} packets, containing the event-specific details. | ||
* | ||
@@ -83,4 +83,3 @@ * Those are the basics that gets us up and running. | ||
this.apiLastSuccess = 0; | ||
const { fetch } = context({ alpnProtocols: ["h2" /* ALPNProtocol.ALPN_HTTP2 */], rejectUnauthorized: false, userAgent: "unifi-access" }); | ||
this.fetch = fetch; | ||
this.fetch = context({ alpnProtocols: ["h2" /* ALPNProtocol.ALPN_HTTP2 */], rejectUnauthorized: false, userAgent: "unifi-access" }).fetch; | ||
this.headers = new Headers(); | ||
@@ -206,2 +205,3 @@ this._isAdminUser = false; | ||
data = await response.json(); | ||
// @eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} | ||
@@ -422,3 +422,3 @@ catch (error) { | ||
// Unlocking only works on hubs. | ||
if (device.device_type !== "UAH") { | ||
if (!device.capabilities?.includes("is_hub")) { | ||
return false; | ||
@@ -428,7 +428,9 @@ } | ||
let action = "unlock"; | ||
let endpoint = "/relay_unlock"; | ||
let endpoint = this.getApiEndpoint("location") + "/" + device.location_id + "/unlock"; | ||
let payload = {}; | ||
// If we've specified a duration, let's specify that. | ||
if (duration !== undefined) { | ||
endpoint = "/lock_rule"; | ||
// eslint-disable-next-line camelcase | ||
const params = new URLSearchParams({ get_result: "true" }); | ||
endpoint = this.getApiEndpoint("device") + "/" + device.unique_id + "/lock_rule?" + params.toString(); | ||
// Safety check for out of bounds values. | ||
@@ -451,3 +453,3 @@ if (duration < 0) { | ||
// Request the unlock from Access. | ||
const response = await this.retrieve(this.getApiEndpoint("device") + "/" + device.unique_id + endpoint, { | ||
const response = await this.retrieve(endpoint, { | ||
body: payload, | ||
@@ -498,3 +500,3 @@ method: "PUT" | ||
// Update Access with the new configuration. | ||
const response = await this.retrieve(this.getApiEndpoint("device") + "/" + device.unique_id + (device.device_type === "UAH" ? "configs" : "settings"), { | ||
const response = await this.retrieve(this.getApiEndpoint("device") + "/" + device.unique_id + (device.capabilities?.includes("is_hub") ? "configs" : "settings"), { | ||
body: JSON.stringify(payload), | ||
@@ -744,2 +746,5 @@ method: "PUT" | ||
break; | ||
case "location": | ||
endpointSuffix = "location"; | ||
break; | ||
case "login": | ||
@@ -746,0 +751,0 @@ endpointPrefix = "/api/"; |
@@ -0,1 +1,2 @@ | ||
import { DeepPartial } from "homebridge-plugin-utils"; | ||
/** | ||
@@ -277,6 +278,2 @@ * UniFi Access API response JSON. | ||
} | ||
/** @ignore */ | ||
export type DeepPartial<T> = { | ||
[P in keyof T]?: T[P] extends Array<infer I> ? Array<DeepPartial<I>> : DeepPartial<T[P]>; | ||
}; | ||
/** @interface */ | ||
@@ -283,0 +280,0 @@ export type AccessBootstrapConfig = Readonly<AccessBootstrapConfigInterface>; |
@@ -1,6 +0,2 @@ | ||
/* Copyright(C) 2019-2024, HJD (https://github.com/hjdhjd). All rights reserved. | ||
* | ||
* access-types.ts: Type definitions for UniFi Access. | ||
*/ | ||
export {}; | ||
//# sourceMappingURL=access-types.js.map |
{ | ||
"name": "unifi-access", | ||
"type": "module", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"displayName": "UniFi Access API", | ||
@@ -46,27 +46,29 @@ "description": "A soon-to-be-almost-complete implementation of the UniFi Access API.", | ||
"scripts": { | ||
"build": "rimraf ./dist && tsc", | ||
"build-docs": " rimraf ./docs/classes ./docs/interfaces ./docs/README.md ./docs/modules.md && npx typedoc", | ||
"clean": "rimraf ./dist", | ||
"lint": "eslint src/**.ts", | ||
"build": "shx rm -rf ./dist && tsc", | ||
"build-docs": "shx rm -f ./docs/[^CO]*.md && npx typedoc", | ||
"clean": "shx rm -rf ./dist", | ||
"lint": "eslint --max-warnings=${ESLINT_MAX_WARNINGS:-\"-1\"} eslint.config.mjs src/**.ts", | ||
"postpublish": "npm run clean", | ||
"prepublishOnly": "npm run lint && npm run build && npm run build-docs", | ||
"test": "eslint src/**.ts", | ||
"watch": "npm run build && npm link && nodemon" | ||
"test": "eslint src/**.ts" | ||
}, | ||
"devDependencies": { | ||
"@stylistic/eslint-plugin": "1.7.0", | ||
"@types/node": "20.12.2", | ||
"@types/ws": "8.5.10", | ||
"@typescript-eslint/eslint-plugin": "7.4.0", | ||
"@typescript-eslint/parser": "7.4.0", | ||
"eslint": "8.57.0", | ||
"rimraf": "5.0.5", | ||
"typedoc": "0.25.12", | ||
"typedoc-plugin-markdown": "3.17.1", | ||
"typescript": "5.4.3" | ||
"@stylistic/eslint-plugin": "2.6.1", | ||
"@types/node": "22.1.0", | ||
"@types/ws": "8.5.12", | ||
"eslint": "9.8.0", | ||
"homebridge-plugin-utils": "1.7.0", | ||
"shx": "0.3.4", | ||
"typedoc": "0.26.5", | ||
"typedoc-plugin-markdown": "4.2.3", | ||
"typescript": "5.5.4", | ||
"typescript-eslint": "8.0.0" | ||
}, | ||
"dependencies": { | ||
"@adobe/fetch": "4.1.1", | ||
"ws": "8.16.0" | ||
"@adobe/fetch": "4.1.8", | ||
"ws": "8.18.0" | ||
}, | ||
"optionalDependencies": { | ||
"bufferutil": "4.0.8" | ||
} | ||
} |
@@ -11,3 +11,3 @@ <SPAN ALIGN="CENTER" STYLE="text-align:center"> | ||
## A complete UniFi Access API implementation. | ||
## Aspiring to a complete UniFi Access API implementation. | ||
</DIV> | ||
@@ -14,0 +14,0 @@ </SPAN> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
85701
0
3
1453
+ Added@adobe/fetch@4.1.8(transitive)
+ Addedbufferutil@4.0.8(transitive)
+ Addeddebug@4.3.5(transitive)
+ Addednode-gyp-build@4.8.2(transitive)
+ Addedws@8.18.0(transitive)
- Removed@adobe/fetch@4.1.1(transitive)
- Removeddebug@4.3.4(transitive)
- Removedws@8.16.0(transitive)
Updated@adobe/fetch@4.1.8
Updatedws@8.18.0