This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Automatic Covers | |
description: A Home Assistant blueprint to automatically set the cover position depending on the sun position | |
domain: automation | |
input: | |
shutter_automatic_input: | |
name: Shutter Automatic Input | |
selector: | |
entity: | |
domain: input_boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Motion-activated Fan | |
description: A Home Assistant blueprint to automatically turn a fan on and off upon motion | |
domain: automation | |
input: | |
motion_entity: | |
name: Motion Sensor | |
selector: | |
entity: | |
fan_target: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Motion-activated Light with illuminance | |
description: Turn on a light when motion is detected and illuminance is below a set Lux level. | |
domain: automation | |
input: | |
action_id: | |
name: Action ID | |
description: 'That is your Action name in snake case, e.g., "automatic_wc_light".' | |
selector: | |
text: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import executeConcurrently from '@/generic/executeConcurrently'; | |
test('Concurrent execution works with decreasing execution time', async () => { | |
const numberOfExecutions = 10; | |
const resolvedExecutions = await testExecution( | |
numberOfExecutions, | |
3, | |
(counter: number) => Math.ceil(100 / counter), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code is taken from Firefox Send (https://github.com/mozilla/send) and slightly modified. | |
export default class StreamSlicer { | |
protected chunkSize: number; | |
protected partialChunk: Uint8Array; | |
protected offset: number; | |
constructor(chunkSize: number) { | |
this.chunkSize = chunkSize; | |
this.partialChunk = new Uint8Array(this.chunkSize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code is taken from Firefox Send (https://github.com/mozilla/send) and slightly modified. | |
export default async function saveFile(plaintext: ArrayBuffer, fileName: string, fileType: string) { | |
return new Promise((resolve, reject) => { | |
const dataView = new DataView(plaintext); | |
const blob = new Blob([dataView], { type: fileType }); | |
if (navigator.msSaveBlob) { | |
navigator.msSaveBlob(blob, fileName); | |
return resolve(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This source code is taken from Firefox Send (https://github.com/mozilla/send) and slightly modified. | |
export default async function splitFile( | |
file: File, | |
chunkSize: number, | |
callback: (chunk: Uint8Array, sequenceNumber: number) => void, | |
transformer?: (chunk: Uint8Array, chunkIndex: number) => any, | |
) { | |
const fileSize = file.size; | |
let offset = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AuthenticatedSecretKeyCryptography { | |
public static readonly KEY_LENGTH_IN_BYTES = 16; | |
public static readonly IV_LENGTH_IN_BYTES = 16; | |
public static readonly TAG_LENGTH_IN_BYTES = 16; | |
private static readonly ALGORITHM = 'AES-GCM'; | |
private readonly secretKey: CryptoKey; | |
private readonly tagLengthInBytes: number; | |
public constructor(secretKey: CryptoKey, tagLengthInBytes = AuthenticatedSecretKeyCryptography.TAG_LENGTH_IN_BYTES) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Crypto } from '@peculiar/webcrypto'; | |
import RandomGenerator from '@/crypto/RandomGenerator'; | |
Object.defineProperty(window, 'crypto', { | |
value: new Crypto(), | |
}); | |
test('Random generator returns a 16 byte random sequence', () => { | |
const randomBytes1 = RandomGenerator.generateRandomBytes(16); | |
const randomBytes2 = RandomGenerator.generateRandomBytes(16); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class RandomGenerator { | |
public static generateRandomBytes(length: number): Uint8Array { | |
return crypto.getRandomValues(new Uint8Array(length)); | |
} | |
public static generateRandomNumber(min: number, max: number): number { | |
const range = max - min; | |
const maxGeneratedValue = 0xFFFFFFFF; | |
const possibleResultValues = range + 1; | |
const possibleGeneratedValues = maxGeneratedValue + 1; |