Skip to content

Commit b3a8ea5

Browse files
committed
feat(types)!: move to TypeScript
Close #1
1 parent e90404d commit b3a8ea5

File tree

157 files changed

+10164
-5207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+10164
-5207
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ async function main () {
117117
main()
118118
```
119119

120+
## About types
121+
122+
From version 2.0, this library is written in TypeScript. Response typing comes from the Netatmo Swagger, transformed into a TS interface by SwaggerEditor.
123+
Errors may be present, so don't hesitate to [create an issue](https://github.com/nioc/netatmo-nodejs-api/issues/new) for fix.
124+
120125
## Versioning
121126

122127
netatmo-nodejs-api is maintained under the [semantic versioning](https://semver.org/) guidelines.

lib/index.d.ts

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import { AxiosRequestConfig } from 'axios';
2+
import querystring from 'querystring';
3+
import type { PublicData, Measure, StationData, Homes, EventsList, CameraImage } from './types/index';
4+
/**
5+
* Basic scope for weather station
6+
*/
7+
declare const SCOPE_BASIC_WEATHER = "read_station";
8+
/**
9+
* Basic scope for camera
10+
*/
11+
declare const SCOPE_BASIC_CAMERA = "read_camera write_camera read_presence";
12+
/**
13+
* Full scope for camera, end user has to provide an explicit consent with autorization code flow
14+
*/
15+
declare const SCOPE_FULL_CAMERA = "read_camera write_camera access_camera read_presence access_presence";
16+
/**
17+
* Full scope for camera and weather station, end user has to provide an explicit consent with autorization code flow
18+
*/
19+
declare const SCOPE_FULL = "read_station read_camera write_camera access_camera read_presence access_presence";
20+
type NetatmoToken = {
21+
access_token: string;
22+
refresh_token: string;
23+
expires_in: number;
24+
};
25+
declare class Token {
26+
accessToken: string | null;
27+
refreshToken: string | null;
28+
expiresInTimestamp: number;
29+
/**
30+
* Create an instance of Token
31+
*
32+
* @param {string} accessToken Access token for your user
33+
* @param {string} refreshToken Refresh token to get a new access token once it has expired
34+
* @param {number} expiresInTimestamp Validity timelaps as timestamp
35+
* @return {Token} A new instance of Token
36+
*/
37+
constructor(accessToken: string | null, refreshToken: string | null, expiresInTimestamp: number);
38+
}
39+
declare class NetatmoClient {
40+
clientId: string;
41+
clientSecret: string;
42+
scope: string;
43+
requestConfig: {};
44+
authorizationCode: string | null;
45+
redirectUrl: string | null;
46+
state: string | null;
47+
refreshToken: string | null;
48+
accessToken: string | null;
49+
expiresInTimestamp: number;
50+
/**
51+
* Create an instance of Netatmo client
52+
*
53+
* @param {string} clientId Your app client_id
54+
* @param {string} clientSecret Your app client_secret
55+
* @param {string} scope Scopes space separated (example: `'read_station read_camera write_camera read_presence'`)
56+
* @param {AxiosRequestConfig} requestConfig HTTP request configuration (see https://axios-http.com/docs/req_config)
57+
* @return {NetatmoClient} A new instance of Netatmo client
58+
*/
59+
constructor(clientId: string, clientSecret: string, scope: string, requestConfig?: AxiosRequestConfig);
60+
/**
61+
* Authenticate with access token or refresh token
62+
*
63+
* @param {string} accessToken Access token for your user
64+
* @param {string} refreshToken Refresh token to get a new access token
65+
* @param {number} expiresInTimestamp Validity timelaps as timestamp
66+
* @return {Token} Token `{accessToken, refreshToken, expiresInTimestamp}`
67+
*/
68+
authenticate(accessToken?: string | null, refreshToken?: string | null, expiresInTimestamp?: number): Promise<Token>;
69+
/**
70+
* Return url for authorize code grant
71+
*
72+
* @param {string} redirectUrl Callback URL of your application
73+
* @param {string} statePrefix Arbitrary string added to state
74+
* @return {string} Url to request as POST method for authorize code grant flow
75+
*/
76+
getAuthorizeUrl(redirectUrl?: string | null, statePrefix?: string): string;
77+
/**
78+
* Authenticate with authorization code
79+
*
80+
* @param {string} authorizationCode Authorization code provided after user authorize your app
81+
* @param {string} redirectUrl Callback URL of your application (must be the same as the one provided in authorize url)
82+
* @param {string} state Arbitrary string (prevent Cross-site Request Forgery)
83+
* @return {Token} Token `{accessToken, refreshToken, expiresInTimestamp}`
84+
*/
85+
authenticateByAuthorizationCode(authorizationCode: string, redirectUrl: string, state: string): Promise<Token>;
86+
/**
87+
* Authenticate with an existing refresh token
88+
*
89+
* @param {string} refreshToken Refresh token to get a new access token
90+
* @return {Token} Token `{accessToken, refreshToken, expiresInTimestamp}`
91+
*/
92+
authenticateByRefreshToken(refreshToken: string): Promise<Token>;
93+
/**
94+
* Store access and refresh tokens (you should not have to use this method)
95+
*
96+
* @param {NetatmoToken} netatmoAuthentication Netatmo API authentication result (with `access_token`, `refresh_token` and `expires_in` attributes)
97+
* @return {Token} Token `{accessToken, refreshToken, expiresInTimestamp}`
98+
*/
99+
setToken(netatmoAuthentication: NetatmoToken): Token;
100+
/**
101+
* Check is an access token is valid and use it
102+
*
103+
* @param {string} accessToken Access token for your user
104+
* @param {number} expiresInTimestamp Validity timelaps as timestamp
105+
* @return {boolean} Access token is valid
106+
*/
107+
checkAndSetAccesToken(accessToken: string | null, expiresInTimestamp: number): boolean;
108+
/**
109+
* Request Netatmo API
110+
*
111+
* @param {string} method HTTP method (`'GET'`, `'POST'`)
112+
* @param {string} path API path (example: `'/api/gethomedata'`)
113+
* @param {object} params Parameters send as query string
114+
* @param {object} data Data to post
115+
* @param {boolean} isRetry This is the second try for this request (default false)
116+
* @return {object|Array} Data in response
117+
*/
118+
request(method: 'GET' | 'POST', path: string, params?: Record<string, any> | null, data?: querystring.ParsedUrlQueryInput | null, isRetry?: boolean): Promise<any>;
119+
/**
120+
* Retrieve user's homes and their topology
121+
*
122+
* @param {string} homeId Filter by the ID of the home you want
123+
* @param {number} size Number of events to retrieve. Default is 30
124+
* @return {Homes} User's homes
125+
*/
126+
getHomes(homeId?: null, size?: number): Promise<Homes>;
127+
/**
128+
* Returns all the events until the one specified in the request. This method is available for Welcome, Presence and the Smart Smoke Alarm
129+
*
130+
* @param {string} homeId Id of the home
131+
* @param {string} eventId Your request will retrieve all the events until this one
132+
* @return {EventsList} Events
133+
*/
134+
getEventsUntil(homeId: string, eventId: string): Promise<EventsList>;
135+
/**
136+
* Returns most recent events. This method is only available for Welcome.
137+
*
138+
* @param {string} homeId Id of the home
139+
* @param {string} personId Your request will retrieve all events of the given home until the most recent event of the given person
140+
* @param {number} offset Number of events to retrieve. Default is 30
141+
* @return {EventsList} Events
142+
*/
143+
getLastEventOf(homeId: string, personId: string, offset: number): Promise<EventsList>;
144+
/**
145+
* Returns previous events. This method is available for Welcome, Presence and the Smart Smoke Alarm
146+
*
147+
* @param {string} homeId Id of the home
148+
* @param {string} eventId Your request will retrieve all the events until this one
149+
* @param {number} size Number of events to retrieve. Default is 30
150+
* @return {EventsList} Events
151+
*/
152+
getNextEvents(homeId: string, eventId: string, size: number): Promise<EventsList>;
153+
/**
154+
* Returns the snapshot associated to an event
155+
*
156+
* @param {string} imageId Id of the image (can be retrieved as "id" in "face" in Gethomedata for Welcome, or as "id" in "snapshot" in Getnextevents, Getlasteventof and Geteventsuntil)
157+
* @param {string} key Security key to access snapshots
158+
* @return {CameraImage} Picture
159+
*/
160+
getCameraPicture(imageId: string, key: string): Promise<CameraImage>;
161+
/**
162+
* Retrieves publicly shared weather data from Outdoor Modules within a predefined area
163+
*
164+
* @param {number} latNE Latitude of the north east corner of the requested area. -85 <= lat_ne <= 85 and lat_ne>lat_sw
165+
* @param {number} lonNE Longitude of the north east corner of the requested area. -180 <= lon_ne <= 180 and lon_ne>lon_sw
166+
* @param {number} latSW Latitude of the south west corner of the requested area. -85 <= lat_sw <= 85
167+
* @param {number} lonSW Longitude of the south west corner of the requested area. -180 <= lon_sw <= 180
168+
* @param {string} requiredData To filter stations based on relevant measurements you want (e.g. rain will only return stations with rain gauges). Available data are {temperature, pressure, humidity, rain, wind}. Default is no filter
169+
* @param {boolean} filter True to exclude station with abnormal temperature measures. Default is false
170+
* @return {PublicData[]} Weather data
171+
*/
172+
getPublicData(latNE: number, lonNE: number, latSW: number, lonSW: number, requiredData: string, filter?: boolean): Promise<PublicData[]>;
173+
/**
174+
* Returns data from a user Weather Stations (measures and device specific data)
175+
*
176+
* @param {string} deviceId Weather station mac address
177+
* @param {boolean} getFavorites To retrieve user's favorite weather stations. Default is false
178+
* @return {StationData} Devices list (`devices`) and user information (`user`)
179+
*/
180+
getStationsData(deviceId: string, getFavorites?: boolean): Promise<StationData>;
181+
/**
182+
* Retrieve data from a device or module
183+
*
184+
* @param {string} deviceId Weather station mac address
185+
* @param {string} moduleId module mac address
186+
* @param {string} scale Timelapse between two measurements (example: `max`, `30min`, `1hour`, `3hours`, `1day`, `1week`, `1month`)
187+
* @param {string} type type of measurements you wanna retrieve, comma separated (example: `Temperature,CO2`, `Temperature`, `CO2`, `Humidity`, `min_temp`, `max_temp`, `min_hum`, `max_hum`, ...)
188+
* @param {number} dateBegin Timestamp of the first measure to retrieve. Default is null
189+
* @param {number} dateEnd Timestamp of the last measure to retrieve. Default is null
190+
* @param {number} limit Maximum number of measurements (default and max are 1024)
191+
* @param {boolean} optimize Determines the format of the answer. Default is true. For mobile apps we recommend True and False if bandwidth isn't an issue as it is easier to parse
192+
* @param {boolean} realTime If scale different than max, timestamps are by default offset + scale/2. To get exact timestamps, use true. Default is false
193+
* @return {Measure[]} Device measure
194+
*/
195+
getMeasure(deviceId: string, moduleId: string, scale: string, type: string, dateBegin: number, dateEnd: number, limit: number, optimize: boolean, realTime: boolean): Promise<Measure[]>;
196+
}
197+
export { NetatmoClient, SCOPE_BASIC_CAMERA, SCOPE_FULL_CAMERA, SCOPE_FULL, SCOPE_BASIC_WEATHER };

0 commit comments

Comments
 (0)