Skip to content

Commit

Permalink
Fixed issue where no devices/stations are found (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
bropat committed Feb 12, 2022
1 parent 234613e commit 1832366
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Please use GitHub issues for this.

## Changelog

### 1.6.6 (2022-02-12)

* (bropat) Fixed issue where no devices/stations are found (#116)

### 1.6.5 (2022-02-08)

* (bropat) Fixed regression in authentication flow introduced when fixing issue #116
Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](_media/eufy-security-client.png)

# eufy-security-client <small>1.6.5</small>
# eufy-security-client <small>1.6.6</small>

> This shared library allows to control [Eufy security devices](https://us.eufylife.com/collections/security) by connecting to the Eufy cloud servers and local/remote stations over p2p
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eufy-security-client",
"version": "1.6.5",
"version": "1.6.6",
"description": "Client to comunicate with Eufy-Security devices",
"author": {
"name": "bropat",
Expand Down Expand Up @@ -58,7 +58,7 @@
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"typescript": "4.5.4"
"typescript": "4.5.5"
},
"bugs": {
"url": "https://github.com/bropat/eufy-security-client/issues"
Expand Down
10 changes: 9 additions & 1 deletion src/eufysecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "path";

import { EufySecurityEvents, EufySecurityConfig, EufySecurityPersistentData } from "./interfaces";
import { HTTPApi } from "./http/api";
import { Devices, FullDevices, Hubs, PropertyValue, RawValues, Stations } from "./http/interfaces";
import { Devices, FullDevices, Hubs, PropertyValue, RawValues, Stations, Houses } from "./http/interfaces";
import { Station } from "./http/station";
import { ConfirmInvite, DeviceListResponse, HouseInviteListResponse, Invite, StationListResponse } from "./http/models";
import { AuthResult, CommandName, NotificationSwitchMode, NotificationType, PropertyName } from "./http/types";
Expand All @@ -31,6 +31,7 @@ export class EufySecurity extends TypedEmitter<EufySecurityEvents> {

private api: HTTPApi;

private houses: Houses = {};
private stations: Stations = {};
private devices: Devices = {};

Expand Down Expand Up @@ -130,6 +131,7 @@ export class EufySecurity extends TypedEmitter<EufySecurityEvents> {
this.api.setLanguage(this.config.language);
this.api.setPhoneModel(this.config.trustedDeviceName);

this.api.on("houses", (houses: Houses) => this.handleHouses(houses));
this.api.on("hubs", (hubs: Hubs) => this.handleHubs(hubs));
this.api.on("devices", (devices: FullDevices) => this.handleDevices(devices));
this.api.on("close", () => this.onAPIClose());
Expand Down Expand Up @@ -352,6 +354,12 @@ export class EufySecurity extends TypedEmitter<EufySecurityEvents> {
throw new StationNotFoundError(`No station with this serial number: ${stationSN}!`);
}

private handleHouses(houses: Houses): void {
this.log.debug("Got houses:", houses);
//TODO: Finish implementation
this.houses = houses;
}

private handleHubs(hubs: Hubs): void {
this.log.debug("Got hubs:", hubs);
const stationsSNs: string[] = Object.keys(this.stations);
Expand Down
17 changes: 16 additions & 1 deletion src/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isValid as isValidLanguage } from "@cospired/i18n-iso-languages";
import { createECDH, ECDH } from "crypto";

import { ResultResponse, LoginResultResponse, TrustDevice, Cipher, Voice, EventRecordResponse, Invite, ConfirmInvite, SensorHistoryEntry, ApiResponse, CaptchaResponse, LoginRequest, HouseDetail, DeviceListResponse, StationListResponse, HouseInviteListResponse, HouseListResponse, PassportProfileResponse } from "./models"
import { HTTPApiEvents, Ciphers, FullDevices, Hubs, Voices, Invites, HTTPApiRequest, HTTPApiPersistentData } from "./interfaces";
import { HTTPApiEvents, Ciphers, FullDevices, Hubs, Voices, Invites, HTTPApiRequest, HTTPApiPersistentData, Houses } from "./interfaces";
import { AuthResult, EventFilterType, PublicKeyType, ResponseErrorCode, StorageType, VerfyCodeTypes } from "./types";
import { ParameterHelper } from "./parameter";
import { encryptPassword, getTimezoneGMTString } from "./utils";
Expand All @@ -33,6 +33,7 @@ export class HTTPApi extends TypedEmitter<HTTPApiEvents> {

private devices: FullDevices = {};
private hubs: Hubs = {};
private houses: Houses = {};

private persistentData: HTTPApiPersistentData = {
user_id: "",
Expand Down Expand Up @@ -422,6 +423,20 @@ export class HTTPApi extends TypedEmitter<HTTPApiEvents> {
public async updateDeviceInfo(): Promise<void> {
//Get the latest device info

//Get Houses
const houses = await this.getHouseList();
if (houses && houses.length > 0) {
houses.forEach(element => {
this.log.debug(`Houses - element: ${JSON.stringify(element)}`);
this.log.debug(`Houses - house name: ${element.house_name}`);
this.houses[element.house_id] = element;
});
if (Object.keys(this.houses).length > 0)
this.emit("houses", this.houses);
} else {
this.log.info("No houses found.");
}

//Get Stations
const stations = await this.getStationList();
if (stations && stations.length > 0) {
Expand Down
7 changes: 6 additions & 1 deletion src/http/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StreamMetadata } from "../p2p/interfaces";
import { CommandResult } from "../p2p/models";
import { AlarmEvent, ChargingType } from "../p2p/types";
import { Camera, Device } from "./device";
import { Cipher, Voice, Invite, DeviceListResponse, StationListResponse } from "./models";
import { Cipher, Voice, Invite, DeviceListResponse, StationListResponse, HouseListResponse } from "./models";
import { Station } from "./station";
import { CommandName, PropertyName } from "./types";

Expand Down Expand Up @@ -39,6 +39,10 @@ export interface Stations {
[index: string]: Station;
}

export interface Houses {
[index: string]: HouseListResponse;
}

export interface Hubs {
[index: string]: StationListResponse;
}
Expand Down Expand Up @@ -130,6 +134,7 @@ export interface HTTPApiPersistentData {
export interface HTTPApiEvents {
"devices": (devices: FullDevices) => void;
"hubs": (hubs: Hubs) => void;
"houses": (houses: Houses) => void;
"connect": () => void;
"close": () => void;
"tfa request": () => void;
Expand Down

0 comments on commit 1832366

Please sign in to comment.