v0.14.25
This commit is contained in:
+2
-47
@@ -26,7 +26,7 @@ const preferredTheme = ['system', 'light', 'dark'].includes(getCookie('gree_cont
|
||||
|
||||
const app = {
|
||||
devices: [], zones: [], groups: [], deviceGroups: [], deviceGroupEnergy: {}, schedules: [], automations: [], flows: [], accessTokens: [], settings: null, system: {}, outdoorTemperature: null,
|
||||
token: localStorage.getItem('gree_controller_token') || '', authTokenSubmitted: false, ws: null, wsTimer: null,
|
||||
token: localStorage.getItem('gree_controller_token') || '', ws: null, wsTimer: null, wsErrorTimer: null, wsOutageStartedAt: 0,
|
||||
currentView: 'dashboard', loading: false, bootstrapReloadPending: false, language: preferredLanguage, theme: preferredTheme, connectionStatus: 'connecting',
|
||||
languages: [], translations: {}, locales: {}, defaultLanguage: DEFAULT_LANGUAGE,
|
||||
historyTab: 'overview', historyData: { zones: [], devices: [], sensors: [] }, historyCounts: {},
|
||||
@@ -128,50 +128,6 @@ const deviceCommandFieldLabel = key => {
|
||||
}[key];
|
||||
return translationKey ? tr(translationKey) : key;
|
||||
};
|
||||
const VERTICAL_LOUVER_OPTIONS = Object.freeze([
|
||||
[0, 'louver.off'],
|
||||
[1, 'louver.fullRangeAuto'],
|
||||
[2, 'louver.vertical.fixedTop'],
|
||||
[3, 'louver.vertical.fixedUpperMiddle'],
|
||||
[4, 'louver.vertical.fixedMiddle'],
|
||||
[5, 'louver.vertical.fixedLowerMiddle'],
|
||||
[6, 'louver.vertical.fixedBottom'],
|
||||
[7, 'louver.vertical.swingTop'],
|
||||
[8, 'louver.vertical.swingUpperMiddle'],
|
||||
[9, 'louver.vertical.swingMiddle'],
|
||||
[10, 'louver.vertical.swingLowerMiddle'],
|
||||
[11, 'louver.vertical.swingBottom'],
|
||||
]);
|
||||
const HORIZONTAL_LOUVER_OPTIONS = Object.freeze([
|
||||
[0, 'louver.off'],
|
||||
[1, 'louver.fullRangeAuto'],
|
||||
[2, 'louver.horizontal.fixedLeft'],
|
||||
[3, 'louver.horizontal.fixedLeftMiddle'],
|
||||
[4, 'louver.horizontal.fixedMiddle'],
|
||||
[5, 'louver.horizontal.fixedRightMiddle'],
|
||||
[6, 'louver.horizontal.fixedRight'],
|
||||
]);
|
||||
const normalizedLouverPosition = value => {
|
||||
if (value === null || value === undefined || value === '') return null;
|
||||
if (value === true || String(value).toLowerCase() === 'true') return 1;
|
||||
if (value === false || String(value).toLowerCase() === 'false') return 0;
|
||||
const numeric = Number(value);
|
||||
return Number.isFinite(numeric) ? numeric : null;
|
||||
};
|
||||
const louverPositionLabel = (axis, value) => {
|
||||
const options = axis === 'horizontal' ? HORIZONTAL_LOUVER_OPTIONS : VERTICAL_LOUVER_OPTIONS;
|
||||
const normalized = normalizedLouverPosition(value);
|
||||
const item = options.find(([raw]) => raw === normalized);
|
||||
return item ? tr(item[1]) : String(value ?? '');
|
||||
};
|
||||
const louverOptions = (axis, selected, { includeNoChange = false } = {}) => {
|
||||
const options = axis === 'horizontal' ? HORIZONTAL_LOUVER_OPTIONS : VERTICAL_LOUVER_OPTIONS;
|
||||
const selectedValue = normalizedLouverPosition(selected);
|
||||
const render = items => items.map(([value, key]) => `<option value="${value}" ${selectedValue === value ? 'selected' : ''}>${esc(tr(key))}</option>`).join('');
|
||||
const noChange = includeNoChange ? `<option value="" ${selectedValue === null ? 'selected' : ''}>${esc(tr('actions.noChange'))}</option>` : '';
|
||||
if (axis !== 'vertical') return `${noChange}${render(options)}`;
|
||||
return `${noChange}${render(options.slice(0, 7))}<optgroup label="${esc(tr('louver.advancedSwingRanges'))}">${render(options.slice(7))}</optgroup>`;
|
||||
};
|
||||
const dateTime = value => value ? new Intl.DateTimeFormat(locale(), { dateStyle: 'short', timeStyle: 'short' }).format(new Date(value)) : '—';
|
||||
const localResumeSeconds = value => {
|
||||
const timestamp = value ? new Date(value).getTime() : NaN;
|
||||
@@ -457,10 +413,9 @@ async function api(path, options = {}) {
|
||||
}
|
||||
const response = await fetch(withBase(path), { ...options, headers, body });
|
||||
if (response.status === 401) {
|
||||
const invalidToken = app.authTokenSubmitted && Boolean(app.token);
|
||||
const invalidToken = Boolean(app.token);
|
||||
const message = invalidToken ? tr('auth.invalid') : tr('auth.required');
|
||||
showTokenDialog(invalidToken ? message : '');
|
||||
app.authTokenSubmitted = false;
|
||||
const error = new Error(message);
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user