Skip to content

Commit

Permalink
increase maximum offset from sunrise/sunset to 6 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsfaber committed Mar 8, 2023
1 parent 5656cf1 commit 90659a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/time-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TimePicker extends LitElement {

@property() _time!: number;

maxOffset = 2;
maxOffset = 6;

get time() {
if (this._time >= 0) return this._time;
Expand Down Expand Up @@ -193,8 +193,8 @@ export class TimePicker extends LitElement {

let offset = this.event == ETimeEvent.Sunrise ? this._time - ts_sunrise : this._time - ts_sunset;

if (offset > 7200) offset = 7200;
else if (offset < -7200) offset = -7200;
if (offset > this.maxOffset * 3600) offset = this.maxOffset * 3600;
else if (offset < -this.maxOffset * 3600) offset = -this.maxOffset * 3600;
this.time = offset;
} else {
this.time = this.event == ETimeEvent.Sunrise ? this._time + ts_sunrise : this._time + ts_sunset;
Expand Down
5 changes: 2 additions & 3 deletions src/data/date-time/relative_time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export const absToRelTime = (
options: { stepSize?: number } = {}
) => {
const res = parseRelativeTime(timeStr);

if (res) return timeStr;
if (res) timeStr = relToAbsTime(timeStr, hass);

const ts = stringToTime(timeStr, hass);

Expand All @@ -45,6 +44,6 @@ export const absToRelTime = (
: stringToTime(sunEntity.attributes.next_setting, hass);

let offset = ts - ts_ref;
if (options.stepSize) offset = roundTime(offset, options.stepSize, { maxHours: 2 });
if (options.stepSize) offset = roundTime(offset, options.stepSize, { maxHours: 6 });
return `${event}${offset > 0 ? '+' : '-'}${timeToString(Math.abs(offset))}`;
};
4 changes: 2 additions & 2 deletions src/editor/scheduler-editor-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ export class SchedulerEditorTime extends LitElement {
value: ETimeEvent.Sunrise,
name: this.hass.localize('ui.panel.config.automation.editor.conditions.type.sun.sunrise'),
icon: 'mdi:weather-sunny',
disabled: Math.abs(deltaSunrise) > 7200,
disabled: Math.abs(deltaSunrise) > 3600 * 6,
},
{
value: ETimeEvent.Sunset,
name: this.hass.localize('ui.panel.config.automation.editor.conditions.type.sun.sunset'),
icon: 'mdi:weather-night',
disabled: Math.abs(deltaSunset) > 7200,
disabled: Math.abs(deltaSunset) > 3600 * 6,
},
];

Expand Down

0 comments on commit 90659a7

Please sign in to comment.