Add battery limit support

This commit is contained in:
Jonas Lochmann
2020-01-13 17:28:14 +01:00
parent dd18b015f6
commit 50766e804a
10 changed files with 248 additions and 11 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -51,6 +51,7 @@ export { SetUserTimezoneAction } from './setusertimezone'
export { SignOutAtDeviceAction } from './signoutatdevice'
export { TriedDisablingDeviceAdminAction } from './trieddisablingdeviceadmin'
export { UpdateAppActivitiesAction } from './updateappactivities'
export { UpdateCategoryBatteryLimitAction } from './updatecategorybatterylimit'
export { UpdateCategoryBlockAllNotificationsAction } from './updatecategoryblockallnotifications'
export { UpdateCategoryBlockedTimesAction } from './updatecategoryblockedtimes'
export { UpdateCategoryTemporarilyBlockedAction } from './updatecategorytemporarilyblocked'
+5 -1
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 Jonas Lochmann
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -42,6 +42,7 @@ import { SerializedSetRelaxPrimaryDeviceAction, SetRelaxPrimaryDeviceAction } fr
import { SerializedSetSendDeviceConnected, SetSendDeviceConnected } from '../setsenddeviceconnected'
import { SerializedSetUserDisableLimitsUntilAction, SetUserDisableLimitsUntilAction } from '../setuserdisablelimitsuntil'
import { SerializedSetUserTimezoneAction, SetUserTimezoneAction } from '../setusertimezone'
import { SerializedUpdateCategoryBatteryLimitAction, UpdateCategoryBatteryLimitAction } from '../updatecategorybatterylimit'
import { SerializedUpdateCategoryBlockAllNotificationsAction, UpdateCategoryBlockAllNotificationsAction } from '../updatecategoryblockallnotifications'
import { SerializedUpdateCategoryBlockedTimesAction, UpdateCategoryBlockedTimesAction } from '../updatecategoryblockedtimes'
import { SerializedUpdateCategoryTemporarilyBlockedAction, UpdateCategoryTemporarilyBlockedAction } from '../updatecategorytemporarilyblocked'
@@ -81,6 +82,7 @@ export type SerializedParentAction =
SerializedSetSendDeviceConnected |
SerializedSetUserDisableLimitsUntilAction |
SerializedSetUserTimezoneAction |
SerializedUpdateCategoryBatteryLimitAction |
SerializedUpdateCategoryBlockAllNotificationsAction |
SerializedUpdateCategoryBlockedTimesAction |
SerializedUpdateCategoryTemporarilyBlockedAction |
@@ -146,6 +148,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return SetUserDisableLimitsUntilAction.parse(action)
} else if (action.type === 'SET_USER_TIMEZONE') {
return SetUserTimezoneAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_BATTERY_LIMIT') {
return UpdateCategoryBatteryLimitAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_BLOCK_ALL_NOTIFICATIONS') {
return UpdateCategoryBlockAllNotificationsAction.parse(action)
} else if (action.type === 'UPDATE_CATEGORY_BLOCKED_TIMES') {
+69
View File
@@ -0,0 +1,69 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { assertIdWithinFamily } from '../util/token'
import { ParentAction } from './basetypes'
export class UpdateCategoryBatteryLimitAction extends ParentAction {
readonly categoryId: string
readonly chargeLimit?: number
readonly mobileLimit?: number
constructor ({ categoryId, chargeLimit, mobileLimit }: {
categoryId: string
chargeLimit?: number
mobileLimit?: number
}) {
super()
assertIdWithinFamily(categoryId)
if (chargeLimit !== undefined) {
if ((!Number.isSafeInteger(chargeLimit)) || chargeLimit < 0 || chargeLimit > 100) {
throw new Error('charge limit out of range')
}
}
if (mobileLimit !== undefined) {
if ((!Number.isSafeInteger(mobileLimit)) || mobileLimit < 0 || mobileLimit > 100) {
throw new Error('mobile limit out of range')
}
}
this.categoryId = categoryId
this.chargeLimit = chargeLimit
this.mobileLimit = mobileLimit
}
serialize = (): SerializedUpdateCategoryBatteryLimitAction => ({
type: 'UPDATE_CATEGORY_BATTERY_LIMIT',
categoryId: this.categoryId,
mobileLimit: this.mobileLimit,
chargeLimit: this.chargeLimit
})
static parse = ({ categoryId, chargeLimit, mobileLimit }: SerializedUpdateCategoryBatteryLimitAction) => (
new UpdateCategoryBatteryLimitAction({ categoryId, chargeLimit, mobileLimit })
)
}
export interface SerializedUpdateCategoryBatteryLimitAction {
type: 'UPDATE_CATEGORY_BATTERY_LIMIT'
categoryId: string
chargeLimit?: number
mobileLimit?: number
}