Skip to content

Commit

Permalink
Support Shared Accounts (#9)
Browse files Browse the repository at this point in the history
* Support Shared Accounts

* Update README.md

Fixes #8
  • Loading branch information
oemich authored Apr 23, 2024
1 parent eed38e6 commit 5a02419
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ The app can be configured using the following environment variables:

The App utilizes an advanced version of the auth mechanism known from Eufy. The Anker App employs a two-step authentication scheme: first, keys are exchanged, and second, the full login payload is encrypted. However, it turns out the original Eufy mechanism still works, so we're using that in this project (credits to [eufy-security-client](https://github.com/bropat/eufy-security-client) for inspiration). This might break at some point!

**Note**: Anker currently permits only one simultaneous login at a time. When you log in from another device, all previously generated auth tokens become invalidated. Thus, if you're utilizing this project, you will be unable to use the app concurrently.
For a "READ-ONLY" access to the data, an account with which the "System" has been shared can be used. By this the main account can still be used in the app to control everything and the shared account can be used for the API access.

**Note**: Anker currently permits only one simultaneous login at a time. When you log in from another device, all previously generated auth tokens become invalidated.

## Disclaimer
This project is the result of some work I did to integrate my Solix into my home automation. I no longer own an Anker Solix Solarbank due to disappointment with the product, so this project will not receive any updates. However, I'm happy to accept pull requests.
Expand Down
8 changes: 8 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ interface SiteHomepageResponse {
solarbank_list: Solarbank[],
}

interface SiteListResponse {
site_list: Site[]
}

export interface UserMqttInfo {
/**
* A unique identifier for the user.
Expand Down Expand Up @@ -377,6 +381,10 @@ export class SolixApi {
const data = {};
return authFetch<SiteHomepageResponse>("/power_service/v1/site/get_site_homepage", data);
},
getSiteList: async () => {
const data = {};
return authFetch<SiteListResponse>("/power_service/v1/site/get_site_list", data);
},
getHomeLoadChart: async ({
siteId,
deviceSn = "", // Was always an empty string
Expand Down
10 changes: 9 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ async function run(): Promise<void> {
const siteHomepage = await loggedInApi.siteHomepage();
let topic = `${config.mqttTopic}/site_homepage`;
await publisher.publish(topic, siteHomepage.data);
for (const site of siteHomepage.data?.site_list ?? []) {

let sites;
if (siteHomepage.data.site_list.length === 0) {
// Fallback for Shared Accounts
sites = (await loggedInApi.getSiteList()).data.site_list;
} else {
sites = siteHomepage.data.site_list;
}
for (const site of sites) {
const scenInfo = await loggedInApi.scenInfo(site.site_id);
topic = `${config.mqttTopic}/site/${site.site_name}/scenInfo`;
await publisher.publish(topic, scenInfo.data);
Expand Down

0 comments on commit 5a02419

Please sign in to comment.