Skip to content

Commit 6945854

Browse files
refactor(weather): change method visibility to private
1 parent 2807859 commit 6945854

5 files changed

Lines changed: 56 additions & 56 deletions

File tree

defaultmodules/weather/providers/pirateweather.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class PirateweatherProvider {
3737
return;
3838
}
3939

40-
this.initializeFetcher();
40+
this.#initializeFetcher();
4141
}
4242

43-
initializeFetcher () {
44-
const url = this.getUrl();
43+
#initializeFetcher () {
44+
const url = this.#getUrl();
4545

4646
this.fetcher = new HTTPFetcher(url, {
4747
reloadInterval: this.config.updateInterval,
@@ -55,7 +55,7 @@ class PirateweatherProvider {
5555
this.fetcher.on("response", async (response) => {
5656
try {
5757
const data = await response.json();
58-
this.handleResponse(data);
58+
this.#handleResponse(data);
5959
} catch (error) {
6060
Log.error("[pirateweather] Parse error:", error);
6161
if (this.onErrorCallback) {
@@ -74,7 +74,7 @@ class PirateweatherProvider {
7474
});
7575
}
7676

77-
handleResponse (data) {
77+
#handleResponse (data) {
7878
if (!data || (!data.currently && !data.daily && !data.hourly)) {
7979
Log.error("[pirateweather] No usable data received");
8080
if (this.onErrorCallback) {
@@ -90,14 +90,14 @@ class PirateweatherProvider {
9090

9191
switch (this.config.type) {
9292
case "current":
93-
weatherData = this.generateCurrentWeather(data);
93+
weatherData = this.#generateCurrent(data);
9494
break;
9595
case "forecast":
9696
case "daily":
97-
weatherData = this.generateForecast(data);
97+
weatherData = this.#generateDaily(data);
9898
break;
9999
case "hourly":
100-
weatherData = this.generateHourly(data);
100+
weatherData = this.#generateHourly(data);
101101
break;
102102
default:
103103
Log.error(`[pirateweather] Unknown weather type: ${this.config.type}`);
@@ -116,7 +116,7 @@ class PirateweatherProvider {
116116
}
117117
}
118118

119-
generateCurrentWeather (data) {
119+
#generateCurrent (data) {
120120
if (!data.currently || typeof data.currently.temperature === "undefined") {
121121
return null;
122122
}
@@ -128,7 +128,7 @@ class PirateweatherProvider {
128128
feelsLikeTemp: data.currently.apparentTemperature != null ? parseFloat(data.currently.apparentTemperature) : null,
129129
windSpeed: data.currently.windSpeed != null ? parseFloat(data.currently.windSpeed) : null,
130130
windFromDirection: data.currently.windBearing || null,
131-
weatherType: this.convertWeatherType(data.currently.icon),
131+
weatherType: this.#convertWeatherType(data.currently.icon),
132132
sunrise: null,
133133
sunset: null
134134
};
@@ -147,7 +147,7 @@ class PirateweatherProvider {
147147
return current;
148148
}
149149

150-
generateForecast (data) {
150+
#generateDaily (data) {
151151
if (!data.daily || !data.daily.data || !data.daily.data.length) {
152152
return [];
153153
}
@@ -159,7 +159,7 @@ class PirateweatherProvider {
159159
date: new Date(forecast.time * 1000),
160160
minTemperature: forecast.temperatureMin != null ? parseFloat(forecast.temperatureMin) : null,
161161
maxTemperature: forecast.temperatureMax != null ? parseFloat(forecast.temperatureMax) : null,
162-
weatherType: this.convertWeatherType(forecast.icon),
162+
weatherType: this.#convertWeatherType(forecast.icon),
163163
snow: 0,
164164
rain: 0,
165165
precipitationAmount: 0,
@@ -188,7 +188,7 @@ class PirateweatherProvider {
188188
return days;
189189
}
190190

191-
generateHourly (data) {
191+
#generateHourly (data) {
192192
if (!data.hourly || !data.hourly.data || !data.hourly.data.length) {
193193
return [];
194194
}
@@ -200,7 +200,7 @@ class PirateweatherProvider {
200200
date: new Date(forecast.time * 1000),
201201
temperature: forecast.temperature !== undefined ? parseFloat(forecast.temperature) : null,
202202
feelsLikeTemp: forecast.apparentTemperature !== undefined ? parseFloat(forecast.apparentTemperature) : null,
203-
weatherType: this.convertWeatherType(forecast.icon),
203+
weatherType: this.#convertWeatherType(forecast.icon),
204204
windSpeed: forecast.windSpeed !== undefined ? parseFloat(forecast.windSpeed) : null,
205205
windFromDirection: forecast.windBearing || null,
206206
precipitationProbability: forecast.precipProbability ? parseFloat(forecast.precipProbability) * 100 : null,
@@ -231,15 +231,15 @@ class PirateweatherProvider {
231231
return hours;
232232
}
233233

234-
getUrl () {
234+
#getUrl () {
235235
const apiBase = this.config.apiBase || "https://api.pirateweather.net";
236236
const weatherEndpoint = this.config.weatherEndpoint || "/forecast";
237237
const units = this.config.units || "us";
238238
const lang = this.config.lang || "en";
239239
return `${apiBase}${weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=${units}&lang=${lang}`;
240240
}
241241

242-
convertWeatherType (weatherType) {
242+
#convertWeatherType (weatherType) {
243243
const weatherTypes = {
244244
"clear-day": "day-sunny",
245245
"clear-night": "night-clear",

defaultmodules/weather/providers/smhi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SMHIProvider {
6363
}
6464

6565
#initializeFetcher () {
66-
const url = this.#getURL();
66+
const url = this.#getUrl();
6767

6868
this.fetcher = new HTTPFetcher(url, {
6969
reloadInterval: this.config.updateInterval,
@@ -387,7 +387,7 @@ class SMHIProvider {
387387
}
388388
}
389389

390-
#getURL () {
390+
#getUrl () {
391391
const lon = this.config.lon.toFixed(6);
392392
const lat = this.config.lat.toFixed(6);
393393
return `https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/${lon}/lat/${lat}/data.json`;

defaultmodules/weather/providers/ukmetofficedatahub.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ class UkMetOfficeDataHubProvider {
120120

121121
switch (this.config.type) {
122122
case "current":
123-
weatherData = this.#generateCurrentWeather(data);
123+
weatherData = this.#generateCurrent(data);
124124
break;
125125
case "forecast":
126126
case "daily":
127-
weatherData = this.#generateForecast(data);
127+
weatherData = this.#generateDaily(data);
128128
break;
129129
case "hourly":
130130
weatherData = this.#generateHourly(data);
@@ -145,7 +145,7 @@ class UkMetOfficeDataHubProvider {
145145
}
146146
}
147147

148-
#generateCurrentWeather (data) {
148+
#generateCurrent (data) {
149149
const timeSeries = data.features[0].properties.timeSeries;
150150
const now = new Date();
151151

@@ -207,7 +207,7 @@ class UkMetOfficeDataHubProvider {
207207
return current;
208208
}
209209

210-
#generateForecast (data) {
210+
#generateDaily (data) {
211211
const timeSeries = data.features[0].properties.timeSeries;
212212
const days = [];
213213
const today = new Date();

defaultmodules/weather/providers/weatherbit.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class WeatherbitProvider {
3939
return;
4040
}
4141

42-
this.initializeFetcher();
42+
this.#initializeFetcher();
4343
}
4444

45-
initializeFetcher () {
46-
const url = this.getUrl();
45+
#initializeFetcher () {
46+
const url = this.#getUrl();
4747

4848
this.fetcher = new HTTPFetcher(url, {
4949
reloadInterval: this.config.updateInterval,
@@ -56,7 +56,7 @@ class WeatherbitProvider {
5656
this.fetcher.on("response", async (response) => {
5757
try {
5858
const data = await response.json();
59-
this.handleResponse(data);
59+
this.#handleResponse(data);
6060
} catch (error) {
6161
Log.error("[weatherbit] Parse error:", error);
6262
if (this.onErrorCallback) {
@@ -75,12 +75,12 @@ class WeatherbitProvider {
7575
});
7676
}
7777

78-
getUrl () {
79-
const endpoint = this.getWeatherEndpoint();
78+
#getUrl () {
79+
const endpoint = this.#getWeatherEndpoint();
8080
return `${this.config.apiBase}${endpoint}?lat=${this.config.lat}&lon=${this.config.lon}&units=M&key=${this.config.apiKey}`;
8181
}
8282

83-
getWeatherEndpoint () {
83+
#getWeatherEndpoint () {
8484
switch (this.config.type) {
8585
case "hourly":
8686
return "/forecast/hourly";
@@ -93,7 +93,7 @@ class WeatherbitProvider {
9393
}
9494
}
9595

96-
handleResponse (data) {
96+
#handleResponse (data) {
9797
if (!data || !data.data || data.data.length === 0) {
9898
Log.error("[weatherbit] No usable data received");
9999
if (this.onErrorCallback) {
@@ -109,14 +109,14 @@ class WeatherbitProvider {
109109

110110
switch (this.config.type) {
111111
case "current":
112-
weatherData = this.generateCurrentWeather(data);
112+
weatherData = this.#generateCurrent(data);
113113
break;
114114
case "forecast":
115115
case "daily":
116-
weatherData = this.generateForecast(data);
116+
weatherData = this.#generateDaily(data);
117117
break;
118118
case "hourly":
119-
weatherData = this.generateHourly(data);
119+
weatherData = this.#generateHourly(data);
120120
break;
121121
default:
122122
Log.error(`[weatherbit] Unknown weather type: ${this.config.type}`);
@@ -128,7 +128,7 @@ class WeatherbitProvider {
128128
}
129129
}
130130

131-
generateCurrentWeather (data) {
131+
#generateCurrent (data) {
132132
if (!data.data[0] || typeof data.data[0].temp === "undefined") {
133133
return null;
134134
}
@@ -141,7 +141,7 @@ class WeatherbitProvider {
141141
humidity: parseFloat(current.rh),
142142
windSpeed: parseFloat(current.wind_spd),
143143
windFromDirection: current.wind_dir || null,
144-
weatherType: this.convertWeatherType(current.weather.icon),
144+
weatherType: this.#convertWeatherType(current.weather.icon),
145145
sunrise: null,
146146
sunset: null
147147
};
@@ -164,7 +164,7 @@ class WeatherbitProvider {
164164
return weather;
165165
}
166166

167-
generateForecast (data) {
167+
#generateDaily (data) {
168168
const days = [];
169169

170170
for (const forecast of data.data) {
@@ -174,14 +174,14 @@ class WeatherbitProvider {
174174
maxTemperature: forecast.max_temp !== undefined ? parseFloat(forecast.max_temp) : null,
175175
precipitationAmount: forecast.precip !== undefined ? parseFloat(forecast.precip) : 0,
176176
precipitationProbability: forecast.pop !== undefined ? parseFloat(forecast.pop) : null,
177-
weatherType: this.convertWeatherType(forecast.weather.icon)
177+
weatherType: this.#convertWeatherType(forecast.weather.icon)
178178
});
179179
}
180180

181181
return days;
182182
}
183183

184-
generateHourly (data) {
184+
#generateHourly (data) {
185185
const hours = [];
186186

187187
for (const forecast of data.data) {
@@ -192,7 +192,7 @@ class WeatherbitProvider {
192192
precipitationProbability: forecast.pop !== undefined ? parseFloat(forecast.pop) : null,
193193
windSpeed: forecast.wind_spd !== undefined ? parseFloat(forecast.wind_spd) : null,
194194
windFromDirection: forecast.wind_dir || null,
195-
weatherType: this.convertWeatherType(forecast.weather.icon)
195+
weatherType: this.#convertWeatherType(forecast.weather.icon)
196196
});
197197
}
198198

@@ -205,7 +205,7 @@ class WeatherbitProvider {
205205
* @param {string} weatherType - Weatherbit icon code
206206
* @returns {string|null} Weathericons.css icon name or null
207207
*/
208-
convertWeatherType (weatherType) {
208+
#convertWeatherType (weatherType) {
209209
const weatherTypes = {
210210
t01d: "day-thunderstorm",
211211
t01n: "night-alt-thunderstorm",

0 commit comments

Comments
 (0)