Compare commits

..

3 Commits

Author SHA1 Message Date
e1f3175b80 Added basic t8531 support. 2025-11-16 17:36:16 -06:00
53123a353e Added support for t8531 2025-11-11 00:18:59 -06:00
32d6133bab Init claude commit. 2025-11-11 00:11:00 -06:00
11 changed files with 251 additions and 10 deletions

130
CLAUDE.md Normal file
View File

@ -0,0 +1,130 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Overview
This is a TypeScript client library for controlling Eufy Security devices by connecting to Eufy cloud servers and local/remote stations over P2P. The library is published to npm as `eufy-security-client`.
**Important:** This project is NOT affiliated with Anker/Eufy Security. It is a personal project maintained in spare time.
## Development Commands
### Build
```bash
npm run build # Full build (compiles TypeScript)
npm run build:ts # TypeScript compilation + copy proto files
```
### Development
```bash
npm run watch # Watch mode (auto-recompile on changes)
npm run watch:ts # Watch TypeScript files only
```
### Linting
```bash
npm run lint # Run ESLint on TypeScript source files
```
### Testing
Currently, there are no tests configured (`npm test` exits with error).
## Architecture
### Core Components
The library is organized into four major subsystems, each with its own directory:
1. **HTTP API (`src/http/`)** - Eufy Cloud API communication
- `api.ts`: Main HTTPApi class handling authentication and cloud requests
- `device.ts`: Device class hierarchy (Camera, Lock, Doorbell, Sensor types, etc.)
- `station.ts`: Station/Hub management
- Uses encrypted API v2 communication with RSA/ECDH key exchange
- Handles authentication including 2FA and captcha
2. **P2P Communication (`src/p2p/`)** - Direct peer-to-peer connection with stations/devices
- `session.ts`: P2PClientProtocol handles UDP-based P2P protocol
- Supports local and remote connectivity to stations
- Handles livestreaming, video download, commands (lock/unlock, enable/disable, etc.)
- Complex packet sequencing and encryption handling
- Supports multiple encryption types (none, type1, type2)
3. **Push Notifications (`src/push/`)** - Unified push message interface
- `service.ts`: PushNotificationService manages FCM-based notifications
- `parser.ts`: Normalizes different push notification types
- Handles motion, person detection, doorbell ring events, etc.
4. **MQTT (`src/mqtt/`)** - MQTT subscription for certain devices
- Supports Smart Lock Touch & Wifi and similar MQTT-enabled devices
### Main Entry Point
- **`src/eufysecurity.ts`**: The `EufySecurity` class is the high-level orchestrator
- Must be initialized with `EufySecurity.initialize()` (async factory pattern)
- Manages all stations, devices, and houses
- Coordinates HTTP API, P2P connections, push notifications, and MQTT
- Emits typed events for device/station state changes
- Handles persistent data storage for credentials and state
### Key Design Patterns
- **Typed Event Emitters**: Uses `tiny-typed-emitter` throughout for type-safe events
- **Async Initialization**: Main classes use static `initialize()` factory methods instead of constructors
- **Persistent Data**: Credentials and session data saved to filesystem (default: `.eufy-security-client/`)
- **Property System**: Devices/stations have a metadata-driven property system with read-only/write restrictions
- **Command Queue**: P2P commands are queued and executed sequentially per station
### Communication Layers
```
EufySecurity (High-level API)
├── HTTPApi (Cloud API for device metadata, authentication)
├── P2PClientProtocol (Direct station communication for commands/streaming)
├── PushNotificationService (Real-time event notifications)
└── MQTTService (MQTT-enabled device events)
```
### Device Hierarchy
All devices inherit from base `Device` class with specialized subclasses:
- Camera types: `Camera`, `IndoorCamera`, `SoloCamera`, `FloodlightCamera`, `WallLightCam`, `GarageCamera`
- Doorbell types: `BatteryDoorbellCamera`, `WiredDoorbellCamera`, `DoorbellLock`
- Lock types: `Lock`, `LockKeypad`
- Sensors: `EntrySensor`, `MotionSensor`
- Other: `Keypad`, `SmartSafe`, `SmartDrop`, `Tracker`
Each device type has specific properties and commands based on hardware capabilities.
## TypeScript Configuration
- Target: ES2022
- Module: Node16 with Node16 resolution
- Strict mode enabled
- Build output: `build/` directory
- Source maps generated
- Declaration files (`.d.ts`) generated for npm package
## Publishing
- Main entry: `build/index.js`
- Requires Node.js >= 20.0.0
- Uses `prepublishOnly` script to ensure build runs before publishing
- Proto files (`.proto`) and certificates (`.crt`) are copied to build directory
## P2P Protocol Notes
The P2P protocol is UDP-based with custom sequencing and encryption:
- Supports local (LAN) and remote (through Eufy cloud) connections
- Uses magic word `0xf1e2d3c4` in packet headers
- Multiple encryption modes with AES and RSA
- Handles livestreaming with separate video/audio packet sequencing
- Energy-saving devices have different keepalive/timeout strategies
- Smart locks use BLE-style command structures wrapped in P2P
## Logging
Uses `typescript-logging` with category-based logging:
- Categories: HTTP, P2P, PUSH, MQTT
- Configurable log levels per category
- Default logger can be replaced via `EufySecurity.initialize()` config

View File

@ -156,7 +156,7 @@ Instructions aimed at maintainers for deploying a new version: [Deployment](docs
### 3.0.0 (2024-03-03)
* (bropat) **Breaking Change** New modular logging implementation
* (bropat) Added support for Video Smart Lock S330 (T8530; #220)
* (bropat) Added support for Video Smart Lock S330 (T8530/T8531; #220)
* (bropat) Added support for Smart Lock C210 (T8502; #291)
* (bropat) Added support for Smart Lock C220 (T8506; #377 #356)
* (bropat) Added support for Smart Lock S230 (T8510P; #458)

View File

@ -1491,7 +1491,8 @@ class Device extends tiny_typed_emitter_1.TypedEmitter {
sn.startsWith("T8502") ||
sn.startsWith("T8504") ||
sn.startsWith("T8506") ||
sn.startsWith("T8530");
sn.startsWith("T8530") ||
sn.startsWith("T8531");
}
static isGarageCameraBySn(sn) {
return sn.startsWith("T8453") ||

File diff suppressed because one or more lines are too long

View File

@ -75,6 +75,7 @@ export declare enum DeviceType {
SMART_TRACK_CARD = 159,//T87B2
LOCK_8502 = 180,
LOCK_8506 = 184,
LOCK_8531 = 189,
WALL_LIGHT_CAM_81A0 = 10005,
INDOOR_PT_CAMERA_C220 = 10008,// T8W11C
INDOOR_PT_CAMERA_C210 = 10009,// T8419 / T8W11P?

View File

@ -967,7 +967,7 @@ exports.GenericTypeProperty = {
52: "Lock Basic No Finger",
53: "Lock Basic Advanced No Finger",
54: "Retrofit Smart Lock E110 (T8503)",
55: "Video Smart Lock S330 (T8530)",
55: "Video Smart Lock S330 (T8530/T8531)",
56: "Lock 85A3",
57: "Lock 8592",
58: "Retrofit Smart Lock E130 (T8504)",

File diff suppressed because one or more lines are too long

View File

@ -65,7 +65,7 @@
| ![T8510 image](_media/smartlock_touch_t8510_small.jpg) | Smart Lock Touch (T8510) | :x: | |
| ![T8510 with Wi-Fi Bridge image](_media/smartlock_touch_t8510_wifibridge_small.jpg) | Smart Lock Touch with Wi-Fi Bridge (T8510) | :heavy_check_mark: :wrench: | |
| ![T8520 image](_media/smartlock_touch_and_wifi_t8520_small.jpg) | Smart Lock Touch & Wifi (T8520) | :heavy_check_mark: :wrench: | Firmware: 1.3.6.8 (20220205), 1.3.8.0 (20220816) |
| ![T8530 image](_media/smartlock_video_t8530_small.jpg) | Video Smart Lock S330 (T8530) | :heavy_check_mark: | Firmware: 1.2.0.2 (20230530) |
| ![T8530 image](_media/smartlock_video_t8530_small.jpg) | Video Smart Lock S330 (T8530/T8531) | :heavy_check_mark: | Firmware: 1.2.0.2 (20230530) |
| ![T8502 image](_media/smartlock_touch_and_wifi_t8502_small.jpg) | Smart Lock C210 (T8502; E110) | :heavy_check_mark: | Firmware: 2.1.1.1 (20230913) |
| ![T8506 image](_media/smartlock_touch_and_wifi_t8506_small.jpg) | Smart Lock C220 (T8506) | :heavy_check_mark: | Firmware: 1.1.3.3 (20231125) |
| ![T8503 image](_media/smartlock_t8503_small.jpg) | Retrofit Smart Lock E110 (T8503; Smart Lock R10) | :heavy_check_mark: | Firmware: 1.0.7.7 (20230622) |

View File

@ -1,5 +1,5 @@
{
"name": "eufy-security-client-dz",
"name": "eufy-security-client",
"version": "3.2.0",
"description": "Client to comunicate with Eufy-Security devices",
"author": {

View File

@ -1238,6 +1238,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
Device.isLockWifiT8502(type);
}
static isLockKeypad(type: number): boolean {
return Device.isLockWifiR10Keypad(type) || Device.isLockWifiR20Keypad(type);
}
@ -1267,7 +1268,7 @@ export class Device extends TypedEmitter<DeviceEvents> {
}
static isLockWifiVideo(type: number): boolean {
return DeviceType.LOCK_8530 == type;
return (DeviceType.LOCK_8530 == type || DeviceType.LOCK_8531 == type);
}
static isLockWifiR10Keypad(type: number): boolean {
@ -1524,7 +1525,8 @@ export class Device extends TypedEmitter<DeviceEvents> {
sn.startsWith("T8502") ||
sn.startsWith("T8504") ||
sn.startsWith("T8506") ||
sn.startsWith("T8530");
sn.startsWith("T8530") ||
sn.startsWith("T8531");
}
static isGarageCameraBySn(sn: string): boolean {

View File

@ -80,6 +80,7 @@ export enum DeviceType {
SMART_TRACK_CARD = 159, //T87B2
LOCK_8502 = 180,
LOCK_8506 = 184,
LOCK_8531 = 189,
WALL_LIGHT_CAM_81A0 = 10005,
INDOOR_PT_CAMERA_C220 = 10008, // T8W11C
INDOOR_PT_CAMERA_C210 = 10009, // T8419 / T8W11P?
@ -986,7 +987,7 @@ export const GenericTypeProperty: PropertyMetadataNumeric = {
52: "Lock Basic No Finger",
53: "Lock Basic Advanced No Finger",
54: "Retrofit Smart Lock E110 (T8503)",
55: "Video Smart Lock S330 (T8530)",
55: "Video Smart Lock S330 (T8530/T8531)",
56: "Lock 85A3",
57: "Lock 8592",
58: "Retrofit Smart Lock E130 (T8504)",
@ -6196,6 +6197,96 @@ export const DeviceProperties: Properties = {
[PropertyName.DeviceNightvisionOptimization]: DeviceNightvisionOptimizationProperty,
[PropertyName.DeviceNightvisionOptimizationSide]: DeviceNightvisionOptimizationSideProperty,
},
[DeviceType.LOCK_8531]: {
...GenericDeviceProperties,
[PropertyName.DeviceBattery]: DeviceBatteryProperty,
[PropertyName.DeviceBatteryTemp]: DeviceBatteryTempProperty,
[PropertyName.DeviceWifiRSSI]: DeviceWifiRSSIProperty,
[PropertyName.DeviceWifiSignalLevel]: DeviceWifiSignalLevelProperty,
[PropertyName.DeviceEnabled]: DeviceEnabledProperty, //OK
[PropertyName.DeviceAutoNightvision]: DeviceAutoNightvisionProperty, //OK
[PropertyName.DeviceMotionDetection]: DeviceMotionDetectionProperty, //OK
[PropertyName.DeviceWatermark]: DeviceWatermarkBatteryDoorbellCamera1Property, //OK
[PropertyName.DeviceState]: DeviceStateProperty,
[PropertyName.DeviceLastChargingDays]: DeviceLastChargingDaysProperty,
[PropertyName.DeviceLastChargingFalseEvents]: DeviceLastChargingFalseEventsProperty,
[PropertyName.DeviceLastChargingRecordedEvents]: DeviceLastChargingRecordedEventsProperty,
[PropertyName.DeviceLastChargingTotalEvents]: DeviceLastChargingTotalEventsProperty,
[PropertyName.DeviceBatteryUsageLastWeek]: DeviceBatteryUsageLastWeekProperty,
[PropertyName.DeviceMotionDetected]: DeviceMotionDetectedProperty,
[PropertyName.DevicePersonDetected]: DevicePersonDetectedProperty,
[PropertyName.DeviceRinging]: DeviceRingingProperty,
[PropertyName.DevicePicture]: DevicePictureProperty,
[PropertyName.DevicePictureUrl]: DevicePictureUrlProperty,
[PropertyName.DeviceSpeakerVolume]: DeviceSpeakerVolumeIndoorFloodDoorbellProperty, //OK
[PropertyName.DeviceRingtoneVolume]: DeviceRingtoneVolumeBatteryDoorbellProperty, //OK
[PropertyName.DeviceAudioRecording]: DeviceAudioRecordingProperty,
[PropertyName.DeviceMotionDetectionType]: DeviceMotionDetectionTypeProperty, // OK
[PropertyName.DevicePowerWorkingMode]: DevicePowerWorkingModeBatteryDoorbellProperty,
[PropertyName.DeviceChargingStatus]: DeviceChargingStatusProperty,
[PropertyName.DeviceRecordingClipLength]: DeviceRecordingClipLengthProperty,
[PropertyName.DeviceRecordingRetriggerInterval]: DeviceRecordingRetriggerIntervalBatteryDoorbellProperty,
[PropertyName.DeviceRecordingEndClipMotionStops]: DeviceRecordingEndClipMotionStopsProperty,
[PropertyName.DeviceVideoStreamingQuality]: DeviceVideoStreamingQualityBatteryDoorbellProperty, //OK
[PropertyName.DeviceVideoRecordingQuality]:DeviceVideoRecordingQualityT8530Property, //OK
[PropertyName.DeviceChimeIndoor]: DeviceChimeIndoorBatteryDoorbellProperty,
[PropertyName.DeviceChimeHomebase]: DeviceChimeHomebaseBatteryDoorbellProperty, //OK
[PropertyName.DeviceChimeHomebaseRingtoneVolume]: DeviceChimeHomebaseRingtoneVolumeBatteryDoorbellProperty, //OK
[PropertyName.DeviceChimeHomebaseRingtoneType]: DeviceChimeHomebaseRingtoneTypeBatteryDoorbellProperty, //OK
[PropertyName.DeviceNotificationType]: DeviceNotificationTypeBatteryDoorbellProperty, //OK
[PropertyName.DeviceNotificationRing]: DeviceNotificationRingProperty, //OK
[PropertyName.DeviceNotificationMotion]: DeviceNotificationMotionProperty, //OK
[PropertyName.DeviceMotionDetectionSensitivityMode]: DeviceMotionDetectionSensitivityModeProperty,
[PropertyName.DeviceMotionDetectionSensitivityStandard]: DeviceMotionDetectionSensitivityStandardProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedA]: DeviceMotionDetectionSensitivityAdvancedAProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedB]: DeviceMotionDetectionSensitivityAdvancedBProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedC]: DeviceMotionDetectionSensitivityAdvancedCProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedD]: DeviceMotionDetectionSensitivityAdvancedDProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedE]: DeviceMotionDetectionSensitivityAdvancedEProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedF]: DeviceMotionDetectionSensitivityAdvancedFProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedG]: DeviceMotionDetectionSensitivityAdvancedGProperty,
[PropertyName.DeviceMotionDetectionSensitivityAdvancedH]: DeviceMotionDetectionSensitivityAdvancedHProperty,
[PropertyName.DeviceLoiteringDetection]: DeviceLoiteringDetectionProperty, //OK
[PropertyName.DeviceLoiteringDetectionLength]: DeviceLoiteringDetectionLengthProperty,
[PropertyName.DeviceLoiteringDetectionRange]: DeviceLoiteringDetectionRangeProperty,
[PropertyName.DeviceLoiteringCustomResponsePhoneNotification]: DeviceLoiteringCustomResponsePhoneNotificationProperty,
[PropertyName.DeviceLoiteringCustomResponseAutoVoiceResponse]: DeviceLoiteringCustomResponseAutoVoiceResponseProperty,
[PropertyName.DeviceLoiteringCustomResponseAutoVoiceResponseVoice]: DeviceLoiteringCustomResponseAutoVoiceResponseVoiceProperty,
[PropertyName.DeviceLoiteringCustomResponseHomeBaseNotification]: DeviceLoiteringCustomResponseHomeBaseNotificationProperty,
[PropertyName.DeviceLoiteringCustomResponseTimeFrom]: DeviceLoiteringCustomResponseTimeFromProperty,
[PropertyName.DeviceLoiteringCustomResponseTimeTo]: DeviceLoiteringCustomResponseTimeToProperty,
[PropertyName.DeviceSomeoneLoitering]: DeviceSomeoneLoiteringProperty,
[PropertyName.DeviceSnooze]: DeviceSnoozeProperty,
[PropertyName.DeviceSnoozeTime]: DeviceSnoozeTimeProperty,
[PropertyName.DeviceSnoozeStartTime]: DeviceSnoozeStartTimeProperty,
[PropertyName.DeviceSnoozeHomebase]: DeviceSnoozeHomebaseProperty,
[PropertyName.DeviceSnoozeChime]: DeviceSnoozeChimeProperty,
[PropertyName.DeviceSnoozeMotion]: DeviceSnoozeMotionProperty,
[PropertyName.DevicePersonName]: DevicePersonNameProperty,
[PropertyName.DeviceLocked]: DeviceLockedProperty,
[PropertyName.DeviceLockStatus]: DeviceBasicLockStatusProperty,
[PropertyName.DeviceLeavingDetection]: DeviceLeavingDetectionProperty,
[PropertyName.DeviceLeavingReactionNotification]: DeviceLeavingReactionNotificationProperty,
[PropertyName.DeviceLeavingReactionStartTime]: DeviceLeavingReactionStartTimeProperty,
[PropertyName.DeviceLeavingReactionEndTime]: DeviceLeavingReactionEndTimeProperty,
[PropertyName.DeviceSomeoneGoing]: DeviceSomeoneGoingProperty,
[PropertyName.DeviceAutoLock]: DeviceAutoLockProperty,
[PropertyName.DeviceAutoLockTimer]: DeviceAutoLockTimerProperty,
[PropertyName.DeviceAutoLockSchedule]: DeviceAutoLockScheduleProperty,
[PropertyName.DeviceAutoLockScheduleStartTime]: DeviceAutoLockScheduleStartTimeProperty,
[PropertyName.DeviceAutoLockScheduleEndTime]: DeviceAutoLockScheduleEndTimeProperty,
[PropertyName.DeviceOneTouchLocking]: DeviceOneTouchLockingProperty,
[PropertyName.DeviceWrongTryProtection]: DeviceWrongTryProtectionProperty,
[PropertyName.DeviceWrongTryAttempts]: DeviceWrongTryAttemptsProperty,
[PropertyName.DeviceWrongTryLockdownTime]: DeviceWrongTryLockdownTimeProperty,
[PropertyName.DeviceScramblePasscode]: DeviceScramblePasscodeProperty,
[PropertyName.DeviceNotificationUnlocked]: DeviceNotificationUnlockedProperty,
[PropertyName.DeviceNotificationLocked]: DeviceNotificationLockedProperty,
[PropertyName.DeviceLockEventOrigin]: DeviceLockEventOriginProperty,
[PropertyName.DeviceBeepVolume]: DeviceBeepVolumeProperty,
[PropertyName.DeviceNightvisionOptimization]: DeviceNightvisionOptimizationProperty,
[PropertyName.DeviceNightvisionOptimizationSide]: DeviceNightvisionOptimizationSideProperty,
},
[DeviceType.FLOODLIGHT]: { // T8420 Firmware: 1.0.0.35 Hardware: 2.2 (20211219)
...GenericDeviceProperties,
[PropertyName.DeviceEnabled]: DeviceEnabledProperty,
@ -9783,6 +9874,22 @@ export const DeviceCommands: Commands = {
CommandName.DeviceUpdateUserSchedule,
CommandName.DeviceUpdateUsername,
],
[DeviceType.LOCK_8531]: [
CommandName.DeviceStartLivestream,
CommandName.DeviceStopLivestream,
CommandName.DeviceQuickResponse,
CommandName.DeviceStartDownload,
CommandName.DeviceCancelDownload,
CommandName.DeviceStartTalkback,
CommandName.DeviceStopTalkback,
CommandName.DeviceSnooze,
CommandName.DeviceLockCalibration,
CommandName.DeviceAddUser,
CommandName.DeviceDeleteUser,
CommandName.DeviceUpdateUserPasscode,
CommandName.DeviceUpdateUserSchedule,
CommandName.DeviceUpdateUsername,
],
[DeviceType.MOTION_SENSOR]: [],
[DeviceType.SENSOR]: [],
[DeviceType.SMART_SAFE_7400]: [