homebridge-tsvesync 1.0.7 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/.cursorrules +177 -0
  2. package/README.md +3 -1
  3. package/dist/accessories/air-purifier.accessory.d.ts +25 -0
  4. package/dist/accessories/air-purifier.accessory.d.ts.map +1 -0
  5. package/dist/accessories/air-purifier.accessory.js +170 -0
  6. package/dist/accessories/air-purifier.accessory.js.map +1 -0
  7. package/dist/accessories/base.accessory.d.ts +78 -0
  8. package/dist/accessories/base.accessory.d.ts.map +1 -0
  9. package/dist/accessories/base.accessory.js +231 -0
  10. package/dist/accessories/base.accessory.js.map +1 -0
  11. package/dist/accessories/fan.accessory.d.ts +22 -0
  12. package/dist/accessories/fan.accessory.d.ts.map +1 -0
  13. package/dist/accessories/fan.accessory.js +166 -0
  14. package/dist/accessories/fan.accessory.js.map +1 -0
  15. package/dist/accessories/humidifier.accessory.d.ts +25 -0
  16. package/dist/accessories/humidifier.accessory.d.ts.map +1 -0
  17. package/dist/accessories/humidifier.accessory.js +162 -0
  18. package/dist/accessories/humidifier.accessory.js.map +1 -0
  19. package/dist/accessories/light.accessory.d.ts +24 -0
  20. package/dist/accessories/light.accessory.d.ts.map +1 -0
  21. package/dist/accessories/light.accessory.js +169 -0
  22. package/dist/accessories/light.accessory.js.map +1 -0
  23. package/dist/accessories/outlet.accessory.d.ts +20 -0
  24. package/dist/accessories/outlet.accessory.d.ts.map +1 -0
  25. package/dist/accessories/outlet.accessory.js +145 -0
  26. package/dist/accessories/outlet.accessory.js.map +1 -0
  27. package/dist/index.d.ts +3 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/platform.d.ts +19 -3
  31. package/dist/platform.d.ts.map +1 -1
  32. package/dist/platform.js +117 -50
  33. package/dist/platform.js.map +1 -1
  34. package/dist/types/device.types.d.ts +69 -0
  35. package/dist/types/device.types.d.ts.map +1 -0
  36. package/dist/types/device.types.js +3 -0
  37. package/dist/types/device.types.js.map +1 -0
  38. package/dist/types/polling.types.d.ts +10 -0
  39. package/dist/types/polling.types.d.ts.map +1 -0
  40. package/dist/types/polling.types.js +49 -0
  41. package/dist/types/polling.types.js.map +1 -0
  42. package/dist/utils/device-factory.d.ts +16 -0
  43. package/dist/utils/device-factory.d.ts.map +1 -0
  44. package/dist/utils/device-factory.js +104 -0
  45. package/dist/utils/device-factory.js.map +1 -0
  46. package/dist/utils/logger.d.ts +53 -0
  47. package/dist/utils/logger.d.ts.map +1 -0
  48. package/dist/utils/logger.js +107 -0
  49. package/dist/utils/logger.js.map +1 -0
  50. package/dist/utils/polling-manager.d.ts +46 -0
  51. package/dist/utils/polling-manager.d.ts.map +1 -0
  52. package/dist/utils/polling-manager.js +107 -0
  53. package/dist/utils/polling-manager.js.map +1 -0
  54. package/dist/utils/retry.d.ts +24 -0
  55. package/dist/utils/retry.d.ts.map +1 -0
  56. package/dist/utils/retry.js +53 -0
  57. package/dist/utils/retry.js.map +1 -0
  58. package/package.json +3 -3
  59. package/src/accessories/air-purifier.accessory.ts +279 -0
  60. package/src/accessories/base.accessory.ts +332 -0
  61. package/src/accessories/fan.accessory.ts +243 -0
  62. package/src/accessories/humidifier.accessory.ts +257 -0
  63. package/src/accessories/light.accessory.ts +255 -0
  64. package/src/accessories/outlet.accessory.ts +205 -0
  65. package/src/index.ts +3 -0
  66. package/src/platform.ts +140 -58
  67. package/src/types/device.types.ts +79 -0
  68. package/src/types/polling.types.ts +59 -0
  69. package/src/utils/device-factory.ts +141 -0
  70. package/src/utils/logger.ts +130 -0
  71. package/src/utils/polling-manager.ts +138 -0
  72. package/src/utils/retry.ts +77 -0
  73. package/dist/platformAccessory.d.ts +0 -21
  74. package/dist/platformAccessory.d.ts.map +0 -1
  75. package/dist/platformAccessory.js +0 -139
  76. package/dist/platformAccessory.js.map +0 -1
  77. package/package/LICENSE +0 -21
  78. package/package/README.md +0 -227
  79. package/package/api/vesync/VeSync.yaml +0 -33
  80. package/package/api/vesyncbulb/ESL100.yaml +0 -74
  81. package/package/api/vesyncbulb/ESL100CW.yaml +0 -123
  82. package/package/api/vesyncbulb/ESL100MC.yaml +0 -169
  83. package/package/api/vesyncbulb/XYD0001.yaml +0 -193
  84. package/package/api/vesyncfan/Classic200S.yaml +0 -280
  85. package/package/api/vesyncfan/Classic300S.yaml +0 -278
  86. package/package/api/vesyncfan/Core200S.yaml +0 -256
  87. package/package/api/vesyncfan/Core300S.yaml +0 -281
  88. package/package/api/vesyncfan/Core400S.yaml +0 -281
  89. package/package/api/vesyncfan/Core600S.yaml +0 -281
  90. package/package/api/vesyncfan/Dual200S.yaml +0 -278
  91. package/package/api/vesyncfan/LAP-C201S-AUSR.yaml +0 -256
  92. package/package/api/vesyncfan/LAP-C202S-WUSR.yaml +0 -256
  93. package/package/api/vesyncfan/LAP-C301S-WAAA.yaml +0 -281
  94. package/package/api/vesyncfan/LAP-C301S-WJP.yaml +0 -281
  95. package/package/api/vesyncfan/LAP-C302S-WUSB.yaml +0 -281
  96. package/package/api/vesyncfan/LAP-C401S-WAAA.yaml +0 -281
  97. package/package/api/vesyncfan/LAP-C401S-WJP.yaml +0 -281
  98. package/package/api/vesyncfan/LAP-C401S-WUSR.yaml +0 -281
  99. package/package/api/vesyncfan/LAP-C601S-WEU.yaml +0 -281
  100. package/package/api/vesyncfan/LAP-C601S-WUS.yaml +0 -281
  101. package/package/api/vesyncfan/LAP-C601S-WUSR.yaml +0 -281
  102. package/package/api/vesyncfan/LAP-EL551S-AEUR.yaml +0 -167
  103. package/package/api/vesyncfan/LAP-EL551S-AUS.yaml +0 -167
  104. package/package/api/vesyncfan/LAP-EL551S-WEU.yaml +0 -167
  105. package/package/api/vesyncfan/LAP-EL551S-WUS.yaml +0 -167
  106. package/package/api/vesyncfan/LAP-V102S-AASR.yaml +0 -167
  107. package/package/api/vesyncfan/LAP-V102S-AUSR.yaml +0 -167
  108. package/package/api/vesyncfan/LAP-V102S-WEU.yaml +0 -167
  109. package/package/api/vesyncfan/LAP-V102S-WJP.yaml +0 -167
  110. package/package/api/vesyncfan/LAP-V102S-WUS.yaml +0 -167
  111. package/package/api/vesyncfan/LAP-V201-AUSR.yaml +0 -167
  112. package/package/api/vesyncfan/LAP-V201S-AASR.yaml +0 -167
  113. package/package/api/vesyncfan/LAP-V201S-AEUR.yaml +0 -167
  114. package/package/api/vesyncfan/LAP-V201S-AUSR.yaml +0 -167
  115. package/package/api/vesyncfan/LAP-V201S-WEU.yaml +0 -167
  116. package/package/api/vesyncfan/LAP-V201S-WJP.yaml +0 -167
  117. package/package/api/vesyncfan/LAP-V201S-WUS.yaml +0 -167
  118. package/package/api/vesyncfan/LEH-S601S-WUS.yaml +0 -303
  119. package/package/api/vesyncfan/LEH-S601S-WUSR.yaml +0 -82
  120. package/package/api/vesyncfan/LTF-F422S-KEU.yaml +0 -165
  121. package/package/api/vesyncfan/LTF-F422S-WUS.yaml +0 -165
  122. package/package/api/vesyncfan/LTF-F422S-WUSR.yaml +0 -167
  123. package/package/api/vesyncfan/LTF-F422_WJP.yaml +0 -165
  124. package/package/api/vesyncfan/LUH-A601S-AUSW.yaml +0 -82
  125. package/package/api/vesyncfan/LUH-A601S-WUSB.yaml +0 -305
  126. package/package/api/vesyncfan/LUH-A602S-WEU.yaml +0 -305
  127. package/package/api/vesyncfan/LUH-A602S-WEUR.yaml +0 -305
  128. package/package/api/vesyncfan/LUH-A602S-WJP.yaml +0 -305
  129. package/package/api/vesyncfan/LUH-A602S-WUS.yaml +0 -305
  130. package/package/api/vesyncfan/LUH-A602S-WUSC.yaml +0 -305
  131. package/package/api/vesyncfan/LUH-A602S-WUSR.yaml +0 -305
  132. package/package/api/vesyncfan/LUH-D301S-WEU.yaml +0 -305
  133. package/package/api/vesyncfan/LUH-D301S-WJP.yaml +0 -305
  134. package/package/api/vesyncfan/LUH-D301S-WUSR.yaml +0 -305
  135. package/package/api/vesyncfan/LUH-M101S-WUS.yaml +0 -278
  136. package/package/api/vesyncfan/LUH-O451S-WEU.yaml +0 -278
  137. package/package/api/vesyncfan/LUH-O451S-WUS.yaml +0 -278
  138. package/package/api/vesyncfan/LUH-O451S-WUSR.yaml +0 -305
  139. package/package/api/vesyncfan/LUH-O601S-KUS.yaml +0 -305
  140. package/package/api/vesyncfan/LUH-O601S-WUS.yaml +0 -305
  141. package/package/api/vesyncfan/LV-PUR131S.yaml +0 -108
  142. package/package/api/vesyncfan/LV-RH131S.yaml +0 -108
  143. package/package/api/vesyncoutlet/ESO15-TB.yaml +0 -124
  144. package/package/api/vesyncoutlet/ESW01-EU.yaml +0 -122
  145. package/package/api/vesyncoutlet/ESW03-USA.yaml +0 -122
  146. package/package/api/vesyncoutlet/ESW15-USA.yaml +0 -156
  147. package/package/api/vesyncoutlet/wifi-switch-1.3.yaml +0 -60
  148. package/package/api/vesyncswitch/ESWD16.yaml +0 -128
  149. package/package/api/vesyncswitch/ESWL01.yaml +0 -56
  150. package/package/api/vesyncswitch/ESWL03.yaml +0 -56
  151. package/package/package.json +0 -53
  152. package/package/src/lib/helpers.ts +0 -290
  153. package/package/src/lib/vesync.ts +0 -530
  154. package/package/src/lib/vesyncBaseDevice.ts +0 -114
  155. package/package/src/lib/vesyncBulb.ts +0 -252
  156. package/package/src/lib/vesyncBulbImpl.ts +0 -215
  157. package/package/src/lib/vesyncFan.ts +0 -447
  158. package/package/src/lib/vesyncFanImpl.ts +0 -848
  159. package/package/src/lib/vesyncOutlet.ts +0 -148
  160. package/package/src/lib/vesyncOutletImpl.ts +0 -284
  161. package/package/src/lib/vesyncSwitch.ts +0 -546
  162. package/package/src/lib/vesyncSwitchImpl.ts +0 -408
  163. package/src/platformAccessory.ts +0 -166
  164. package/src/tsvesync.d.ts +0 -26
  165. package/tsvesync-1.0.11.tgz +0 -0
package/.cursorrules ADDED
@@ -0,0 +1,177 @@
1
+ You are a senior TypeScript programmer with preference for clean programming and design patterns.Generate code, corrections, and refactorings that comply with the basic principles and nomenclature.
2
+
3
+ TypeScript and Homebridge Plugin Development Guidelines
4
+
5
+ General TypeScript Guidelines
6
+
7
+ Core Principles
8
+ • Language and Documentation: All code and documentation must be written in English.
9
+ • Type Safety: Types must be explicitly declared for all variables and functions, including parameters and return values.
10
+ • Avoid any: Refrain from using the any type. Create specific types when necessary to ensure type safety.
11
+ • Documentation: Document all public classes and methods using JSDoc to enhance readability and maintainability.
12
+ • Code Structure: Maintain a clean code structure without blank lines within functions to ensure concise and readable code.
13
+ • Export Strategy: Follow the single export per file principle to promote modularity and clarity.
14
+
15
+ Naming Conventions
16
+
17
+ Case Styles
18
+ • Classes: Use PascalCase for class names (e.g., LightAccessory).
19
+ • Variables, Functions, and Methods: Use camelCase for naming (e.g., isConnected, initializeDevice).
20
+ • Files and Directories: Use kebab-case for file and directory names (e.g., light-accessory.ts).
21
+ • Environment Variables: Use UPPERCASE for environment variable names (e.g., HOMEKIT_PIN).
22
+
23
+ Naming Rules
24
+ • Avoid Magic Numbers: Replace magic numbers with named constants to improve code clarity (e.g., const DEFAULT_BRIGHTNESS = 100;).
25
+ • Function Names: Begin all function names with a verb to indicate action (e.g., getStatus, setBrightness).
26
+ • Boolean Variables: Use verb prefixes for boolean variables to clearly indicate their purpose (e.g., isOnline, hasError, canUpdate).
27
+ • Use Complete Words: Prefer complete words over abbreviations, except for:
28
+ • Standard Terms: Such as API, URL, etc.
29
+ • Common Programming Abbreviations:
30
+ • i, j for loop iterators
31
+ • err for errors
32
+ • ctx for contexts
33
+
34
+ Function Guidelines
35
+
36
+ General Rules
37
+ • Conciseness: Keep functions concise and focused, ideally under 20 instructions.
38
+ • Naming: Use verb-noun combinations for function names to clearly describe their actions (e.g., fetchDeviceStatus, updateFirmware).
39
+ • Return Type Prefixes:
40
+ • Boolean Returns: Use prefixes like isX, hasX, canX (e.g., isConnected).
41
+ • Void Returns: Use prefixes like executeX, saveX (e.g., executeCommand).
42
+
43
+ Best Practices
44
+ • Minimize Nesting:
45
+ • Utilize early returns and validation checks to reduce nested code blocks.
46
+ • Extract utility functions to handle repetitive tasks.
47
+ • Higher-Order Functions: Leverage higher-order functions such as map, filter, and reduce for data transformations.
48
+ • Arrow Functions: Implement arrow functions for simple operations with fewer than three instructions.
49
+ • Named Functions: Use named functions for more complex operations to enhance readability and debuggability.
50
+ • Default Parameters: Set default parameter values instead of performing null checks within functions.
51
+ • RO-RO Principle:
52
+ • Receive Object: Accept objects when a function requires multiple parameters.
53
+ • Return Object: Return objects when a function needs to provide multiple values.
54
+ • Abstraction Levels: Maintain a single level of abstraction within functions to ensure clarity and simplicity.
55
+
56
+ Data Management
57
+ • Composite Types: Encapsulate data within composite types (e.g., interfaces, classes) rather than using primitive types directly.
58
+ • Internal Validation: Use classes with internal validation logic instead of standalone validation functions to ensure data integrity.
59
+ • Immutability:
60
+ • Use readonly for static properties to prevent modification.
61
+ • Use as const for immutable literals to enforce constant values.
62
+
63
+ Class Design
64
+
65
+ SOLID Guidelines
66
+ • SOLID Principles: Adhere to SOLID principles to create robust and maintainable classes.
67
+ • Composition Over Inheritance: Favor composition to build complex functionalities from simpler components rather than relying heavily on inheritance.
68
+ • Interface Contracts: Define clear contracts through interfaces to ensure consistent implementation and facilitate testing.
69
+
70
+ Size Constraints
71
+ • Manageable Classes:
72
+ • Limit classes to a maximum of 200 instructions to maintain readability.
73
+ • Restrict to a maximum of 10 public methods to ensure focused responsibilities.
74
+ • Limit to a maximum of 10 properties to avoid complexity.
75
+
76
+ Error Handling
77
+ • Use Exceptions: Employ exceptions for unexpected error scenarios to manage unexpected states gracefully.
78
+ • Exception Handling Practices:
79
+ • Address anticipated issues with appropriate error messages.
80
+ • Provide additional context to errors to aid in debugging.
81
+ • Defer to global error handlers when suitable to centralize error management.
82
+
83
+ Testing Practices
84
+
85
+ General Testing
86
+ • Testing Structure: Organize tests using the Arrange-Act-Assert pattern to ensure clarity and consistency.
87
+ • Naming Conventions: Use clear and descriptive variable names in tests, such as inputData, mockDevice, actualResult, expectedOutcome.
88
+ • Unit Tests: Write unit tests for all public functions to verify their behavior in isolation.
89
+ • Test Doubles: Implement test doubles (mocks, stubs) for dependencies to isolate units under test, except for lightweight third-party dependencies.
90
+ • Acceptance Tests: Create acceptance tests per module using the Given-When-Then format to validate end-to-end functionality.
91
+
92
+ Homebridge Plugin Specific Guidelines
93
+
94
+ Architectural Structure
95
+
96
+ Plugin Organization
97
+ • Modular Architecture: Implement a modular architecture to separate concerns and enhance maintainability.
98
+ • Plugin Structure: Structure your Homebridge plugin with clear directories and files, such as:
99
+ • Accessories: Define accessory classes that represent HomeKit accessories.
100
+ • Services: Implement services that handle specific functionalities of accessories.
101
+ • Types: Define TypeScript types and interfaces for strong type safety.
102
+ • Utils: Include utility functions and helpers for common tasks.
103
+ • Main Entry Point: Create a single entry point file (e.g., index.ts) that registers the plugin with Homebridge.
104
+
105
+ Core Components
106
+ • Accessory Classes:
107
+ • Extend Homebridge’s AccessoryPlugin interface to create custom accessories.
108
+ • Implement required methods like getServices to define the services provided by the accessory.
109
+ • Service Implementations:
110
+ • Utilize Homebridge’s built-in services or create custom services as needed.
111
+ • Implement characteristics with appropriate getters and setters to interact with HomeKit.
112
+ • Configuration Management:
113
+ • Define clear and validated configuration schemas using class-validator or similar libraries.
114
+ • Provide default configurations where applicable to simplify setup.
115
+
116
+ Shared Resources
117
+ • Utility Functions: Place common utility functions in a shared directory to promote reusability.
118
+ • Common Business Logic: Encapsulate shared business logic in separate modules to avoid duplication and enhance clarity.
119
+
120
+ Best Practices
121
+ • Domain-Specific Modules: Keep modules focused on specific domains or functionalities to maintain clarity and separation of concerns.
122
+ • DTO Validation: Implement robust validation at the Data Transfer Object (DTO) level to ensure incoming configurations and data are valid.
123
+ • Separation of Concerns: Maintain a clear separation between different parts of the plugin, such as configuration handling, accessory management, and service implementation.
124
+ • Dependency Injection: Follow Homebridge’s patterns for dependency injection to manage dependencies efficiently and promote testability.
125
+ • Appropriate Decorators: Use TypeScript decorators where applicable to enhance code readability and functionality, such as for dependency injection or metadata definition.
126
+
127
+ Integration with Homebridge APIs
128
+ • Homebridge Interfaces: Utilize Homebridge’s provided interfaces and classes to ensure compatibility and leverage built-in functionalities.
129
+ • Event Handling: Implement event listeners for Homebridge events to respond to changes in accessory states or HomeKit interactions.
130
+ • Asynchronous Operations: Handle asynchronous operations using async/await to maintain readability and manage promises effectively.
131
+ • Logging: Use Homebridge’s logging mechanisms to provide meaningful logs for debugging and monitoring plugin behavior.
132
+
133
+ Plugin Registration
134
+ • Registering Accessories: Ensure all accessories are properly registered with Homebridge using the api.registerAccessory method.
135
+ • Plugin Metadata: Define clear and accurate metadata in the package.json file, including name, version, description, and dependencies.
136
+ • Compatibility: Ensure compatibility with the latest Homebridge versions and adhere to any API changes or deprecations.
137
+
138
+ Configuration Handling
139
+ • Schema Definitions: Define clear configuration schemas using TypeScript interfaces and validate configurations during plugin initialization.
140
+ • Default Values: Provide sensible default values for configuration options to simplify user setup and prevent errors.
141
+ • Error Reporting: Report configuration errors clearly to guide users in correcting their setup.
142
+
143
+ Performance Considerations
144
+ • Efficient Code: Write efficient code to minimize the performance impact on Homebridge and ensure responsive interactions with HomeKit.
145
+ • Resource Management: Manage resources effectively, such as network connections or file handles, to prevent leaks and ensure stability.
146
+ • Asynchronous Operations: Optimize asynchronous operations to prevent blocking the event loop and maintain plugin responsiveness.
147
+
148
+ Security Practices
149
+ • Input Validation: Rigorously validate all inputs and configurations to prevent security vulnerabilities.
150
+ • Sensitive Data Handling: Handle sensitive data, such as credentials, securely by using environment variables or secure storage mechanisms.
151
+ • Dependency Management: Regularly update dependencies to address security vulnerabilities and maintain plugin integrity.
152
+
153
+ Example Directory Structure
154
+
155
+ homebridge-plugin/
156
+ ├── src/
157
+ │ ├── accessories/
158
+ │ │ └── LightAccessory.ts
159
+ │ ├── services/
160
+ │ │ └── LightService.ts
161
+ │ ├── types/
162
+ │ │ └── Config.ts
163
+ │ ├── utils/
164
+ │ │ └── logger.ts
165
+ │ └── index.ts
166
+ ├── tests/
167
+ │ ├── accessories/
168
+ │ │ └── LightAccessory.test.ts
169
+ │ └── services/
170
+ │ └── LightService.test.ts
171
+ ├── package.json
172
+ ├── tsconfig.json
173
+ └── README.md
174
+
175
+ Conclusion
176
+
177
+ Adhering to these TypeScript and Homebridge plugin development guidelines will ensure the creation of robust, maintainable, and high-quality plugins. Emphasizing type safety, clean code principles, modular architecture, and thorough testing will contribute to a seamless integration with Homebridge and a reliable user experience.
package/README.md CHANGED
@@ -118,7 +118,9 @@ Add the following to your Homebridge `config.json`:
118
118
  "platform": "TSVESyncPlatform",
119
119
  "name": "TSVESync",
120
120
  "username": "YOUR_VESYNC_EMAIL",
121
- "password": "YOUR_VESYNC_PASSWORD"
121
+ "password": "YOUR_VESYNC_PASSWORD",
122
+ "updateInterval": 30,
123
+ "debug": false
122
124
  }
123
125
  ]
124
126
  }
@@ -0,0 +1,25 @@
1
+ import { PlatformAccessory } from 'homebridge';
2
+ import { BaseAccessory } from './base.accessory';
3
+ import { TSVESyncPlatform } from '../platform';
4
+ import { DeviceCapabilities, VeSyncAirPurifier } from '../types/device.types';
5
+ export declare class AirPurifierAccessory extends BaseAccessory {
6
+ protected readonly device: VeSyncAirPurifier;
7
+ constructor(platform: TSVESyncPlatform, accessory: PlatformAccessory, device: VeSyncAirPurifier);
8
+ protected setupService(): void;
9
+ protected updateDeviceSpecificStates(details: any): void;
10
+ protected getDeviceCapabilities(): DeviceCapabilities;
11
+ private getActive;
12
+ private setActive;
13
+ private getCurrentAirPurifierState;
14
+ private getTargetAirPurifierState;
15
+ private setTargetAirPurifierState;
16
+ private getAirQuality;
17
+ private getPM25Density;
18
+ private getRotationSpeed;
19
+ private setRotationSpeed;
20
+ private getLockPhysicalControls;
21
+ private setLockPhysicalControls;
22
+ private getFilterChangeIndication;
23
+ private getFilterLifeLevel;
24
+ }
25
+ //# sourceMappingURL=air-purifier.accessory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"air-purifier.accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/air-purifier.accessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE9E,qBAAa,oBAAqB,SAAQ,aAAa;IACrD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;gBAG3C,QAAQ,EAAE,gBAAgB,EAC1B,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,iBAAiB;IAM3B,SAAS,CAAC,YAAY,IAAI,IAAI;IAmF9B,SAAS,CAAC,0BAA0B,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IA0DxD,SAAS,CAAC,qBAAqB,IAAI,kBAAkB;YAcvC,SAAS;YAIT,SAAS;YAeT,0BAA0B;YAI1B,yBAAyB;YAIzB,yBAAyB;YAezB,aAAa;YAMb,cAAc;YAMd,gBAAgB;YAOhB,gBAAgB;YAehB,uBAAuB;YAIvB,uBAAuB;YAmBvB,yBAAyB;YAIzB,kBAAkB;CAGjC"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AirPurifierAccessory = void 0;
4
+ const base_accessory_1 = require("./base.accessory");
5
+ class AirPurifierAccessory extends base_accessory_1.BaseAccessory {
6
+ constructor(platform, accessory, device) {
7
+ super(platform, accessory, device);
8
+ this.device = device;
9
+ }
10
+ setupService() {
11
+ // Get or create the air purifier service
12
+ this.service = this.accessory.getService(this.platform.Service.AirPurifier) ||
13
+ this.accessory.addService(this.platform.Service.AirPurifier);
14
+ // Set up required characteristics
15
+ this.setupCharacteristic(this.platform.Characteristic.Active, this.getActive.bind(this), this.setActive.bind(this));
16
+ this.setupCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.getCurrentAirPurifierState.bind(this));
17
+ this.setupCharacteristic(this.platform.Characteristic.TargetAirPurifierState, this.getTargetAirPurifierState.bind(this), this.setTargetAirPurifierState.bind(this));
18
+ // Set up optional characteristics based on device capabilities
19
+ const capabilities = this.getDeviceCapabilities();
20
+ if (capabilities.hasAirQuality) {
21
+ // Create a separate Air Quality service for air quality characteristics
22
+ const airQualityService = this.accessory.getService(this.platform.Service.AirQualitySensor) ||
23
+ this.accessory.addService(this.platform.Service.AirQualitySensor);
24
+ // Add air quality characteristics to the Air Quality service
25
+ this.setupCharacteristic(this.platform.Characteristic.AirQuality, this.getAirQuality.bind(this), undefined, undefined, airQualityService);
26
+ this.setupCharacteristic(this.platform.Characteristic.PM2_5Density, this.getPM25Density.bind(this), undefined, undefined, airQualityService);
27
+ }
28
+ if (capabilities.hasSpeed) {
29
+ this.setupCharacteristic(this.platform.Characteristic.RotationSpeed, this.getRotationSpeed.bind(this), this.setRotationSpeed.bind(this));
30
+ }
31
+ if (capabilities.hasChildLock) {
32
+ this.setupCharacteristic(this.platform.Characteristic.LockPhysicalControls, this.getLockPhysicalControls.bind(this), this.setLockPhysicalControls.bind(this));
33
+ }
34
+ // Add filter maintenance characteristics
35
+ this.setupCharacteristic(this.platform.Characteristic.FilterChangeIndication, this.getFilterChangeIndication.bind(this));
36
+ this.setupCharacteristic(this.platform.Characteristic.FilterLifeLevel, this.getFilterLifeLevel.bind(this));
37
+ // Add Name characteristic
38
+ this.setupCharacteristic(this.platform.Characteristic.Name, async () => this.device.deviceName);
39
+ }
40
+ updateDeviceSpecificStates(details) {
41
+ const capabilities = this.getDeviceCapabilities();
42
+ if (capabilities.hasAirQuality) {
43
+ const airQualityService = this.accessory.getService(this.platform.Service.AirQualitySensor);
44
+ if (airQualityService && details.airQuality !== undefined && details.airQuality !== null) {
45
+ airQualityService.updateCharacteristic(this.platform.Characteristic.AirQuality, this.convertAirQualityToHomeKit(details.airQuality));
46
+ airQualityService.updateCharacteristic(this.platform.Characteristic.PM2_5Density, details.airQuality);
47
+ }
48
+ }
49
+ if (capabilities.hasSpeed && details.speed !== undefined && details.speed !== null) {
50
+ const normalizedSpeed = Math.min(Math.max((details.speed / (this.device.maxSpeed || 1)) * 100, 0), 100);
51
+ this.updateCharacteristicValue(this.platform.Characteristic.RotationSpeed, normalizedSpeed);
52
+ }
53
+ if (capabilities.hasChildLock && details.childLock !== undefined) {
54
+ this.updateCharacteristicValue(this.platform.Characteristic.LockPhysicalControls, details.childLock ? 1 : 0);
55
+ }
56
+ if (details.filterLife !== undefined && details.filterLife !== null) {
57
+ this.updateCharacteristicValue(this.platform.Characteristic.FilterChangeIndication, details.filterLife <= 20 ? 1 : 0);
58
+ this.updateCharacteristicValue(this.platform.Characteristic.FilterLifeLevel, details.filterLife);
59
+ }
60
+ // Update air purifier state
61
+ const isActive = details.deviceStatus === 'on';
62
+ this.updateCharacteristicValue(this.platform.Characteristic.Active, isActive ? 1 : 0);
63
+ this.updateCharacteristicValue(this.platform.Characteristic.CurrentAirPurifierState, isActive ? 2 : 0 // 0 = INACTIVE, 2 = PURIFYING_AIR
64
+ );
65
+ }
66
+ getDeviceCapabilities() {
67
+ return {
68
+ hasBrightness: false,
69
+ hasColorTemp: false,
70
+ hasColor: false,
71
+ hasSpeed: true,
72
+ hasHumidity: false,
73
+ hasAirQuality: true,
74
+ hasWaterLevel: false,
75
+ hasChildLock: true,
76
+ hasSwingMode: false,
77
+ };
78
+ }
79
+ async getActive() {
80
+ return this.device.deviceStatus === 'on' ? 1 : 0;
81
+ }
82
+ async setActive(value) {
83
+ try {
84
+ const isOn = value === 1;
85
+ const success = isOn ? await this.device.turnOn() : await this.device.turnOff();
86
+ if (!success) {
87
+ throw new Error(`Failed to turn ${isOn ? 'on' : 'off'} device`);
88
+ }
89
+ await this.persistDeviceState('deviceStatus', isOn ? 'on' : 'off');
90
+ }
91
+ catch (error) {
92
+ this.handleDeviceError('set active state', error);
93
+ }
94
+ }
95
+ async getCurrentAirPurifierState() {
96
+ return this.device.deviceStatus === 'on' ? 2 : 0; // 0 = INACTIVE, 2 = PURIFYING_AIR
97
+ }
98
+ async getTargetAirPurifierState() {
99
+ return this.device.mode === 'auto' ? 1 : 0; // 0 = MANUAL, 1 = AUTO
100
+ }
101
+ async setTargetAirPurifierState(value) {
102
+ try {
103
+ const mode = value === 1 ? 'auto' : 'manual';
104
+ const success = await this.device.setMode(mode);
105
+ if (!success) {
106
+ throw new Error(`Failed to set mode to ${mode}`);
107
+ }
108
+ await this.persistDeviceState('mode', mode);
109
+ }
110
+ catch (error) {
111
+ this.handleDeviceError('set target state', error);
112
+ }
113
+ }
114
+ async getAirQuality() {
115
+ return this.device.airQuality !== undefined && this.device.airQuality !== null
116
+ ? this.convertAirQualityToHomeKit(this.device.airQuality)
117
+ : 0;
118
+ }
119
+ async getPM25Density() {
120
+ return this.device.airQuality !== undefined && this.device.airQuality !== null
121
+ ? this.device.airQuality
122
+ : 0;
123
+ }
124
+ async getRotationSpeed() {
125
+ if (this.device.speed === undefined || this.device.speed === null || !this.device.maxSpeed) {
126
+ return 0;
127
+ }
128
+ return Math.min(Math.max((this.device.speed / this.device.maxSpeed) * 100, 0), 100);
129
+ }
130
+ async setRotationSpeed(value) {
131
+ try {
132
+ const speed = Math.round((value / 100) * this.device.maxSpeed);
133
+ const success = await this.device.setSpeed(speed);
134
+ if (!success) {
135
+ throw new Error(`Failed to set speed to ${speed}`);
136
+ }
137
+ await this.persistDeviceState('speed', speed);
138
+ }
139
+ catch (error) {
140
+ this.handleDeviceError('set rotation speed', error);
141
+ }
142
+ }
143
+ async getLockPhysicalControls() {
144
+ return this.device.childLock ? 1 : 0;
145
+ }
146
+ async setLockPhysicalControls(value) {
147
+ try {
148
+ if (!this.device.setChildLock) {
149
+ throw new Error('Device does not support child lock');
150
+ }
151
+ const enabled = value === 1;
152
+ const success = await this.device.setChildLock(enabled);
153
+ if (!success) {
154
+ throw new Error(`Failed to ${enabled ? 'enable' : 'disable'} child lock`);
155
+ }
156
+ await this.persistDeviceState('childLock', enabled);
157
+ }
158
+ catch (error) {
159
+ this.handleDeviceError('set child lock', error);
160
+ }
161
+ }
162
+ async getFilterChangeIndication() {
163
+ return this.device.filterLife <= 20 ? 1 : 0;
164
+ }
165
+ async getFilterLifeLevel() {
166
+ return this.device.filterLife;
167
+ }
168
+ }
169
+ exports.AirPurifierAccessory = AirPurifierAccessory;
170
+ //# sourceMappingURL=air-purifier.accessory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"air-purifier.accessory.js","sourceRoot":"","sources":["../../src/accessories/air-purifier.accessory.ts"],"names":[],"mappings":";;;AACA,qDAAiD;AAIjD,MAAa,oBAAqB,SAAQ,8BAAa;IAGrD,YACE,QAA0B,EAC1B,SAA4B,EAC5B,MAAyB;QAEzB,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAES,YAAY;QACpB,yCAAyC;QACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC;YACzE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAE/D,kCAAkC;QAClC,IAAI,CAAC,mBAAmB,CACtB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,EACnC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EACzB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAC1B,CAAC;QAEF,IAAI,CAAC,mBAAmB,CACtB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,uBAAuB,EACpD,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3C,CAAC;QAEF,IAAI,CAAC,mBAAmB,CACtB,IAAI,CAAC,QAAQ,C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AAI;YACF,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;gBAC7B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;aACvD;YAED,MAAM,OAAO,GAAG,KAAe,KAAK,CAAC,CAAC;YACtC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAExD,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,aAAa,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,aAAa,CAAC,CAAC;aAC3E;YAED,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SACrD;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;SACjD;IACH,CAAC;IAEO,KAAK,CAAC,yBAAyB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IAEO,KAAK,CAAC,kBAAkB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAChC,CAAC;CACF;AAjRD,oDAiRC"}
@@ -0,0 +1,78 @@
1
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
2
+ import { TSVESyncPlatform } from '../platform';
3
+ import { DeviceCapabilities, VeSyncDeviceWithPower } from '../types/device.types';
4
+ export declare abstract class BaseAccessory {
5
+ protected service: Service;
6
+ protected readonly platform: TSVESyncPlatform;
7
+ protected readonly accessory: PlatformAccessory;
8
+ protected readonly device: VeSyncDeviceWithPower;
9
+ private readonly pollingManager;
10
+ private readonly retryManager;
11
+ private readonly logger;
12
+ constructor(platform: TSVESyncPlatform, accessory: PlatformAccessory, device: VeSyncDeviceWithPower);
13
+ /**
14
+ * Get base context for logging
15
+ */
16
+ private getLogContext;
17
+ /**
18
+ * Execute an operation with retry logic
19
+ */
20
+ protected withRetry<T>(operation: () => Promise<T>, operationName: string): Promise<T>;
21
+ /**
22
+ * Set up the device-specific service
23
+ */
24
+ protected abstract setupService(): void;
25
+ /**
26
+ * Update device-specific states
27
+ */
28
+ protected abstract updateDeviceSpecificStates(details: any): void;
29
+ /**
30
+ * Get device capabilities
31
+ */
32
+ protected abstract getDeviceCapabilities(): DeviceCapabilities;
33
+ /**
34
+ * Get the device type for polling configuration
35
+ */
36
+ protected getDeviceType(): string;
37
+ /**
38
+ * Set up the accessory services and start polling
39
+ */
40
+ private setupAccessory;
41
+ /**
42
+ * Start polling for device updates
43
+ */
44
+ protected startPolling(): void;
45
+ /**
46
+ * Stop polling for device updates
47
+ */
48
+ protected stopPolling(): void;
49
+ /**
50
+ * Update the polling manager with the device's active state
51
+ */
52
+ protected updatePollingState(isActive: boolean): void;
53
+ /**
54
+ * Sync the device state with VeSync
55
+ */
56
+ protected syncDeviceState(): Promise<void>;
57
+ /**
58
+ * Helper method to convert air quality values to HomeKit format
59
+ */
60
+ protected convertAirQualityToHomeKit(pm25: number): number;
61
+ /**
62
+ * Helper method to set up a characteristic with get/set handlers
63
+ */
64
+ protected setupCharacteristic(characteristic: any, onGet?: () => Promise<CharacteristicValue>, onSet?: (value: CharacteristicValue) => Promise<void>, props?: Record<string, any>, service?: Service): void;
65
+ /**
66
+ * Helper method to update a characteristic value
67
+ */
68
+ protected updateCharacteristicValue(characteristic: any, value: CharacteristicValue): void;
69
+ /**
70
+ * Persist device state to accessory context
71
+ */
72
+ protected persistDeviceState(key: string, value: unknown): Promise<void>;
73
+ /**
74
+ * Handle device errors consistently
75
+ */
76
+ protected handleDeviceError(operation: string, error: unknown): void;
77
+ }
78
+ //# sourceMappingURL=base.accessory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/base.accessory.ts"],"names":[],"mapp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