Skip to content

Commit

Permalink
Add more Dachs Settings to prevent startup during daytime
Browse files Browse the repository at this point in the history
  • Loading branch information
theimo1221 committed Sep 7, 2024
1 parent 2972f31 commit 2cb2ec1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
## **WORK IN PROGRESS**
* (theimo1221) Update packages
-->

## **WORK IN PROGRESS**

* (theimo1221) Add more Dachs Settings to prevent startup during daytime

## 3.0.0-alpha.85 (2024-09-07)

* (theimo1221) Update packages
Expand Down
10 changes: 10 additions & 0 deletions src/models/deviceSettings/dachsSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export class DachsDeviceSettings extends ActuatorSettings {
*/
public batteryLevelTurnOnThreshold: number = -1;

/**
* Defines the battery level at which the dachs should be turned on,
* in evening hours to prevent a battery based island-system to run out of
* power overnight.
* @default -1 --> No turn on for battery loading
*
* Uses {@link iBatteryDevice.addBatteryLevelCallback}
*/
public batteryLevelBeforeNightTurnOnThreshold: number = -1;

/**
* Defines the battery level below which the dachs should be allowed to start
*/
Expand Down
31 changes: 28 additions & 3 deletions src/server/devices/dachs/dachs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ import {
RestoreTargetAutomaticValueCommand,
RoomBase,
TemperatureSensorChangeAction,
TimeOfDay,
} from '../../../models';
import { API, LogDebugType, OwnSonosDevice, ServerLogService, SettingsService, Utils } from '../../services';
import {
API,
LogDebugType,
OwnSonosDevice,
ServerLogService,
SettingsService,
SunTimeOffsets,
TimeCallbackService,
Utils,
} from '../../services';
import _ from 'lodash';
import { iDachsSettings } from '../../config/iDachsSettings';
import { DachsDeviceSettings } from '../../../models/deviceSettings/dachsSettings';
Expand Down Expand Up @@ -294,8 +304,23 @@ export class Dachs implements iBaseDevice, iActuator {
return;
}
}
if (this._dachsOn || this.settings.batteryLevelTurnOnThreshold < action.newLevel) {
// We are already running, or battery level is high enough.
if (this._dachsOn) {
// We are already running
return;
}

const dayType: TimeOfDay = TimeCallbackService.dayType(new SunTimeOffsets());

if (
(dayType === TimeOfDay.Daylight || dayType === TimeOfDay.BeforeSunrise) &&
action.newLevel > this.settings.batteryLevelTurnOnThreshold
) {
// It is daytime (maybe solar power) and it is no critical battery level
return;
}

if (action.newLevel > this.settings.batteryLevelBeforeNightTurnOnThreshold) {
// It is not daylight but battery level is high enough
return;
}

Expand Down

0 comments on commit 2cb2ec1

Please sign in to comment.