api

package
v0.0.28-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2022 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReminder

func AddReminder(w http.ResponseWriter, r *http.Request)

Adds a new reminder to the database

func AddRoom

func AddRoom(w http.ResponseWriter, r *http.Request)

func AddSwitchPermission

func AddSwitchPermission(w http.ResponseWriter, r *http.Request)

Add a switchPermission to a given user, admin authentication required Request: `{"username": "x", "switch": "y"}` | Response: Response

func AddUser

func AddUser(w http.ResponseWriter, r *http.Request)

Creates a new user and gives him a provided password Request: `{"username": "x", "password": "y"}`, admin auth required

func AddUserPermission

func AddUserPermission(w http.ResponseWriter, r *http.Request)

Adds a given permission to a given user, admin authentication required If the permission is invalid, a `422` is returned Request: `{"username": "", "permission": ""}` | Response: Response

func ChangeActivationAutomation

func ChangeActivationAutomation(w http.ResponseWriter, r *http.Request)

Activate or deactivate the entire automation system

func CreateCamera

func CreateCamera(w http.ResponseWriter, r *http.Request)

Creates a new camera with the provided metadata

func CreateNewAutomation

func CreateNewAutomation(w http.ResponseWriter, r *http.Request)

Creates a new automation

func CreateNewHomescript

func CreateNewHomescript(w http.ResponseWriter, r *http.Request)

Creates a new Homescript

func CreateNewSchedule

func CreateNewSchedule(w http.ResponseWriter, r *http.Request)

Creates a new generic schedule which runs homescript

func CreateSwitch

func CreateSwitch(w http.ResponseWriter, r *http.Request)

Creates a switch in the database

func DebugInfo

func DebugInfo(w http.ResponseWriter, r *http.Request)

Reading system debug information, admin authentication required Todo: read raspberry pi information

func DeleteAllUserNotifications

func DeleteAllUserNotifications(w http.ResponseWriter, r *http.Request)

func DeleteAvatar

func DeleteAvatar(w http.ResponseWriter, r *http.Request)

Deletes the user's currently saved avatar and sets it to default, authentication required

func DeleteCamera

func DeleteCamera(w http.ResponseWriter, r *http.Request)

func DeleteHomescriptById

func DeleteHomescriptById(w http.ResponseWriter, r *http.Request)

Deletes a Homescript by its Id, checks if it exists and if the user has permission to delete it

func DeleteReminder

func DeleteReminder(w http.ResponseWriter, r *http.Request)

Deletes a reminder, for example if it's task is finished

func DeleteRoom

func DeleteRoom(w http.ResponseWriter, r *http.Request)

Deletes a room and all its dependencies

func DeleteSwitch

func DeleteSwitch(w http.ResponseWriter, r *http.Request)

func DeleteUser

func DeleteUser(w http.ResponseWriter, r *http.Request)

Deletes a user given a valid username This also needs to delete any data that depends on this user in terms of a foreign key Admin auth required

func DeleteUserNotificationById

func DeleteUserNotificationById(w http.ResponseWriter, r *http.Request)

Delete a given notification from the current user

func FlushAllLogs

func FlushAllLogs(w http.ResponseWriter, r *http.Request)

Triggers deletion of ALL internal server logs, admin authentication required Request: empty | Response: Response

func FlushOldLogs

func FlushOldLogs(w http.ResponseWriter, r *http.Request)

Triggers deletion of internal server logs which are older than 30 days, admin authentication required Request: empty | Response: Response

func GetAllCameras

func GetAllCameras(w http.ResponseWriter, _ *http.Request)

Returns a list of available cameras as JSON to the user, admin authentication is required because such information is confidential

func GetAllSwitches

func GetAllSwitches(w http.ResponseWriter, r *http.Request)

Returns a list of available switches as JSON to the user, no authentication required

func GetAvatar

func GetAvatar(w http.ResponseWriter, r *http.Request)

Returns the user's current avatar as an image, authentication required

func GetCameraFeed

func GetCameraFeed(w http.ResponseWriter, r *http.Request)

/Camera feed and image fetching ///

func GetCurrentUserPermissions

func GetCurrentUserPermissions(w http.ResponseWriter, r *http.Request)

Returns a list of strings which represent permissions of the currently logged in user, admin authentication required Request: empty | Response: `["a", "b", "c"]`

func GetForeignUserAvatar

func GetForeignUserAvatar(w http.ResponseWriter, r *http.Request)

Returns the avatar of any given user. Used for the user management panel

func GetForeignUserPermissions

func GetForeignUserPermissions(w http.ResponseWriter, r *http.Request)

Returns a list of strings which represent the permissions of an arbitrary user, admin authentication required

func GetForeignUserSwitchPermissions

func GetForeignUserSwitchPermissions(w http.ResponseWriter, r *http.Request)

Returns a list of strings which represent the switch permissions of an arbitrary user, admin authentication required

func GetNotificationCount

func GetNotificationCount(w http.ResponseWriter, r *http.Request)

Returns a uin16 that indicates the number of notifications the current user has, no authentication required

func GetNotifications

func GetNotifications(w http.ResponseWriter, r *http.Request)

Returns a list containing notifications of the current user

func GetPowerStates

func GetPowerStates(w http.ResponseWriter, r *http.Request)

Returns a list of power states, no authentication required Request: empty | Response: `[{"switchId": "x", power: false}, {...}]`

func GetReminders

func GetReminders(w http.ResponseWriter, r *http.Request)

Returns a list of reminders that the current user has added

func GetUserAutomations

func GetUserAutomations(w http.ResponseWriter, r *http.Request)

Returns a list of all automations set up by the current user

func GetUserCameras

func GetUserCameras(w http.ResponseWriter, r *http.Request)

Only returns cameras to which the user has access to, authentication required

func GetUserDetails

func GetUserDetails(w http.ResponseWriter, r *http.Request)

Returns the user's personal data, auth required

func GetUserHomescriptById

func GetUserHomescriptById(w http.ResponseWriter, r *http.Request)

Returns the metadata of an arbitrary homescript-id to which the user has access to

func GetUserSchedules

func GetUserSchedules(w http.ResponseWriter, r *http.Request)

Returns a list of all schedules set up by the current user

func GetUserSwitches

func GetUserSwitches(w http.ResponseWriter, r *http.Request)

Only returns switches which the user has access to, authentication required

func HandleAvatarUpload

func HandleAvatarUpload(w http.ResponseWriter, r *http.Request)

Accepts the upload of an image of following allowed formats (png / webp / jpeg / jpg) Image should ideally be in `1:1` aspect ratio, authentication required`

func HealthCheck

func HealthCheck(w http.ResponseWriter, r *http.Request)

Runs a healthcheck of most systems on which the appplication relies on, will be used by e.g `Uptime Kuma`, no authentication required

func InitLogger

func InitLogger(logger *logrus.Logger)

func ListAllRoomsWithSwitches

func ListAllRoomsWithSwitches(w http.ResponseWriter, r *http.Request)

Returns list of all rooms

func ListLogs

func ListLogs(w http.ResponseWriter, r *http.Request)

Returns a list of logging items in the logging table, admin authentication required

func ListPermissions

func ListPermissions(w http.ResponseWriter, r *http.Request)

Returns the list of all available permissions

func ListPersonalHomescripts

func ListPersonalHomescripts(w http.ResponseWriter, r *http.Request)

Returns a list of homescripts which are owned by the current user

func ListUserRoomsWithSwitches

func ListUserRoomsWithSwitches(w http.ResponseWriter, r *http.Request)

Returns list of rooms which contain switches that the user is allowed to use

func ListUsers

func ListUsers(w http.ResponseWriter, r *http.Request)

Returns a list of users and their metadata, admin auth required

func ModifyAutomation

func ModifyAutomation(w http.ResponseWriter, r *http.Request)

Modifies a existing automation, also restarts the schedule

func ModifyCamera

func ModifyCamera(w http.ResponseWriter, r *http.Request)

func ModifyCurrentUserMetadata

func ModifyCurrentUserMetadata(w http.ResponseWriter, r *http.Request)

Modifies the metadata of the current user

func ModifyHomescript

func ModifyHomescript(w http.ResponseWriter, r *http.Request)

Modifies the metadata of a given homescript

func ModifyReminder

func ModifyReminder(w http.ResponseWriter, r *http.Request)

Modifies a reminder given its id and new metadata

func ModifyRoomData

func ModifyRoomData(w http.ResponseWriter, r *http.Request)

Modifies the room's name and description

func ModifySchedule

func ModifySchedule(w http.ResponseWriter, r *http.Request)

Modify a generic schedule which already exists

func ModifySwitch

func ModifySwitch(w http.ResponseWriter, r *http.Request)

func ModifyUserMetadata

func ModifyUserMetadata(w http.ResponseWriter, r *http.Request)

Modifies the metadata of a given user

func PowerPostHandler

func PowerPostHandler(w http.ResponseWriter, r *http.Request)

API endpoint for manipulating power states and (de) activating sockets, authentication required Permission and switch permission is needed to interact with this endpoint

func RemoveAutomation

func RemoveAutomation(w http.ResponseWriter, r *http.Request)

Stops, then removes the given automation from the system

func RemoveSchedule

func RemoveSchedule(w http.ResponseWriter, r *http.Request)

Stops, then removes the given schedule from the system

func RemoveSwitchPermission

func RemoveSwitchPermission(w http.ResponseWriter, r *http.Request)

Removes a given switch permission from a given user, admin authentication required Request: `{"username": "x", "switch": "y"}` | Response: Response

func RemoveUserPermission

func RemoveUserPermission(w http.ResponseWriter, r *http.Request)

Todo: unit tests for some of the subfunction Removes a given permission from a user, admin authentication required Request: `{"username": "x", "permission": "y"}` | Response: Response

func Res

func Res(w http.ResponseWriter, res Response)

func RunHomescriptString

func RunHomescriptString(w http.ResponseWriter, r *http.Request)

Runs any given Homescript as a string

func SetCurrentUserColorTheme

func SetCurrentUserColorTheme(w http.ResponseWriter, r *http.Request)

Allows the user to change whether they want to use the light or dark theme

func SetCurrentUserSchedulerEnabled

func SetCurrentUserSchedulerEnabled(w http.ResponseWriter, r *http.Request)

Set if the user scheduler is enabled or disabled

func SetUserColorTheme

func SetUserColorTheme(w http.ResponseWriter, r *http.Request)

func SetUserSchedulerEnabled

func SetUserSchedulerEnabled(w http.ResponseWriter, r *http.Request)

Set if the user scheduler is enabled or disabled

func UpdateLocation

func UpdateLocation(w http.ResponseWriter, r *http.Request)

Admin endpoints for changing the servers global configuration

Types

type AddCameraRequest

type AddCameraRequest struct {
	Id     string `json:"id"`
	Name   string `json:"name"`
	Url    string `json:"url"`
	RoomId string `json:"roomId"`
}

type AddReminderRequest

type AddReminderRequest struct {
	Name        string                        `json:"name"`
	Description string                        `json:"description"`
	Priority    database.NotificationPriority `json:"priority"`
	DueDate     uint                          `json:"dueDate"` // Will be sent as unix millis
}

type AddSwitchRequest

type AddSwitchRequest struct {
	Id     string `json:"id"`
	Name   string `json:"name"`
	RoomId string `json:"roomId"`
	Watts  uint16 `json:"watts"`
}

type AddUserRequest

type AddUserRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type AddedReminderResponse

type AddedReminderResponse struct {
	Id      uint   `json:"id"`
	Success bool   `json:"success"`
	Message string `json:"message"`
}

type AutomationActivationRequest

type AutomationActivationRequest struct {
	Enabled bool `json:"enabled"`
}

type CreateHomescriptRequest

type CreateHomescriptRequest struct {
	Id                  string `json:"id"`
	Name                string `json:"name"`
	Description         string `json:"description"`
	QuickActionsEnabled bool   `json:"quickActionsEnabled"`
	SchedulerEnabled    bool   `json:"schedulerEnabled"`
	Code                string `json:"code"`
	MDIcon              string `json:"mdIcon"`
}

type CurrentUserSchedulerEnabledRequest

type CurrentUserSchedulerEnabledRequest struct {
	Enabled bool `json:"enabled"`
}

type DeleteAutomationRequest

type DeleteAutomationRequest struct {
	Id uint `json:"id"`
}

type DeleteCameraRequest

type DeleteCameraRequest struct {
	Id string `json:"id"`
}

type DeleteNotificationByIdRequest

type DeleteNotificationByIdRequest struct {
	Id uint `json:"id"`
}

type DeleteRoomRequest

type DeleteRoomRequest struct {
	Id string `json:"id"`
}

type DeleteScheduleRequest

type DeleteScheduleRequest struct {
	Id uint `json:"id"`
}

type DeleteSwitchRequest

type DeleteSwitchRequest struct {
	Id string `json:"id"`
}

type HomescriptIdRequest

type HomescriptIdRequest struct {
	Id string `json:"id"`
}

type HomescriptLiveRunRequest

type HomescriptLiveRunRequest struct {
	Code string `json:"code"`
}

type HomescriptResponse

type HomescriptResponse struct {
	Success  bool                         `json:"success"`
	Exitcode int                          `json:"exitCode"`
	Message  string                       `json:"message"`
	Output   string                       `json:"output"`
	Errors   []homescript.HomescriptError `json:"error"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type ModifyAutomationRequest

type ModifyAutomationRequest struct {
	Id           uint                `json:"id"`
	Name         string              `json:"name"`
	Description  string              `json:"description"`
	Hour         uint                `json:"hour"`
	Minute       uint                `json:"minute"`
	Days         []uint8             `json:"days"`
	HomescriptId string              `json:"homescriptId"`
	Enabled      bool                `json:"enabled"`
	TimingMode   database.TimingMode `json:"timingMode"`
}

type ModifyCameraRequest

type ModifyCameraRequest struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	Url  string `json:"url"`
}

type ModifyForeignUserMetadataRequest

type ModifyForeignUserMetadataRequest struct {
	Username string                    `json:"username"`
	Data     ModifyUserMetadataRequest `json:"data"`
}

type ModifyGenericScheduleRequest

type ModifyGenericScheduleRequest struct {
	Id             uint   `json:"id"`
	Name           string `json:"name"`
	Hour           uint   `json:"hour"`
	Minute         uint   `json:"minute"`
	HomescriptCode string `json:"homescriptCode"` // Will be executed if the scheduler runs the job
}

type ModifyPowerScheduleRequest

type ModifyPowerScheduleRequest struct {
	Id        uint                    `json:"id"`
	Name      string                  `json:"name"`
	Hour      uint                    `json:"hour"`
	Minute    uint                    `json:"minute"`
	PowerJobs []hardware.PowerRequest `json:"powerJobs"` // Will be parsed to HMS code
}

type ModifyReminderRequest

type ModifyReminderRequest struct {
	Id          uint                          `json:"id"`
	Name        string                        `json:"name"`
	Description string                        `json:"description"`
	Priority    database.NotificationPriority `json:"priority"`
	DueDate     uint                          `json:"dueDate"` // Will be sent as unix millis
}

type ModifySwitchRequest

type ModifySwitchRequest struct {
	Id    string `json:"id"`
	Name  string `json:"name"`
	Watts uint16 `json:"watts"`
}

type ModifyUserMetadataRequest

type ModifyUserMetadataRequest struct {
	Forename          string `json:"forename"`
	Surname           string `json:"surname"`
	PrimaryColorDark  string `json:"primaryColorDark"`
	PrimaryColorLight string `json:"primaryColorLight"`
}

type NewAutomationRequest

type NewAutomationRequest struct {
	Name         string              `json:"name"`
	Description  string              `json:"description"`
	Hour         uint                `json:"hour"`   // 24 >= h >= 0 | Can only be used with minute, specifies the exact hour in which the automation will run, 0 is midnight, 15 is 3PM, 3 is 3AM -> 24h format
	Minute       uint                `json:"minute"` // 60 >= m >= 0 | Can only be used with hour, specifies the exact minute on which the automation will run
	Days         []uint8             `json:"days"`   //  6 >= d >= 0 | Can contain 7 elements at maximum, value `0` represents Sunday, value `6` represents Saturday
	HomescriptId string              `json:"homescriptId"`
	Enabled      bool                `json:"enabled"`
	TimingMode   database.TimingMode `json:"timingMode"`
}

type NewPowerScheduleRequest

type NewPowerScheduleRequest struct {
	Name      string                  `json:"name"`
	Hour      uint                    `json:"hour"`
	Minute    uint                    `json:"minute"`
	PowerJobs []hardware.PowerRequest `json:"powerJobs"`
}

type NewScheduleRequest

type NewScheduleRequest struct {
	Name           string `json:"name"`
	Hour           uint   `json:"hour"`
	Minute         uint   `json:"minute"`
	HomescriptCode string `json:"homescriptCode"` // Will be executed if the scheduler runs the job
}

type NotificationCountResponse

type NotificationCountResponse struct {
	NotificationCount uint16 `json:"count"`
}

type PowerRequest

type PowerRequest struct {
	Switch  string `json:"switch"`
	PowerOn bool   `json:"powerOn"`
}

type RemoveReminderRequest

type RemoveReminderRequest struct {
	Id uint `json:"id"`
}

type RemoveUserRequest

type RemoveUserRequest struct {
	Username string `json:"username"`
}

type Response

type Response struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
	Error   string `json:"error"`
	Time    string `json:"time"`
}

type RoomRequest

type RoomRequest struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type SetColorThemeRequest

type SetColorThemeRequest struct {
	DarkTheme bool `json:"darkTheme"`
}

type SetForeignUserColorThemeRequest

type SetForeignUserColorThemeRequest struct {
	Username  string `json:"username"`
	DarkTheme bool   `json:"darkTheme"`
}

type UpdateLocationRequest

type UpdateLocationRequest struct {
	Latitude  float32 `json:"latitude"`
	Longitude float32 `json:"longitude"`
}

type UserPermissionRequest

type UserPermissionRequest struct {
	Username   string `json:"username"`
	Permission string `json:"permission"`
}

type UserSchedulerEnabledRequest

type UserSchedulerEnabledRequest struct {
	Username string `json:"username"`
	Enabled  bool   `json:"enabled"`
}

type UserSwitchPermissionRequest

type UserSwitchPermissionRequest struct {
	Username string `json:"username"`
	Switch   string `json:"switch"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL