|
| 1 | +import assert from "node:assert"; |
| 2 | +import {describe, expect, it} from "vitest"; |
| 3 | +import {findByDevice} from "../src/index"; |
| 4 | +import type {DefinitionExposesFunction, Expose} from "../src/lib/types"; |
| 5 | +import {mockDevice} from "./utils"; |
| 6 | + |
| 7 | +const getFeatureNames = (expose: Expose): string[] => { |
| 8 | + return "features" in expose ? expose.features.map((feature) => feature.name) : []; |
| 9 | +}; |
| 10 | + |
| 11 | +describe("Shelly 2PM Gen4 cover mode", () => { |
| 12 | + it("exposes lift-only covers by default and opt-in tilt controls", async () => { |
| 13 | + const device = mockDevice({ |
| 14 | + modelID: "2PM", |
| 15 | + manufacturerName: "Shelly", |
| 16 | + endpoints: [ |
| 17 | + {ID: 1, profileID: 260, deviceID: 514, inputClusterIDs: [0, 3, 4, 5, 258], outputClusterIDs: []}, |
| 18 | + {ID: 239, profileID: 49153, deviceID: 8193, inputClusterIDs: [64513, 64514], outputClusterIDs: []}, |
| 19 | + {ID: 242, profileID: 41440, deviceID: 97, inputClusterIDs: [], outputClusterIDs: [33]}, |
| 20 | + ], |
| 21 | + }); |
| 22 | + const definition = await findByDevice(device); |
| 23 | + expect(definition.model).toBe("S4SW-002P16EU-COVER"); |
| 24 | + expect(typeof definition.exposes).toBe("function"); |
| 25 | + const exposes = definition.exposes as DefinitionExposesFunction; |
| 26 | + |
| 27 | + const defaultCover = exposes(device, {}).find((expose) => expose.type === "cover"); |
| 28 | + const tiltCover = exposes(device, {cover_tilt_enabled: "true"}).find((expose) => expose.type === "cover"); |
| 29 | + assert(defaultCover); |
| 30 | + assert(tiltCover); |
| 31 | + |
| 32 | + expect(getFeatureNames(defaultCover)).toContain("position"); |
| 33 | + expect(getFeatureNames(defaultCover)).not.toContain("tilt"); |
| 34 | + expect(getFeatureNames(tiltCover)).toContain("position"); |
| 35 | + expect(getFeatureNames(tiltCover)).toContain("tilt"); |
| 36 | + expect(definition.options?.some((option) => option.name === "cover_tilt_enabled")).toBe(true); |
| 37 | + }); |
| 38 | +}); |
0 commit comments