-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cz.smarteon.loxone | ||
|
||
/** | ||
* Represents Loxone authentication method. | ||
*/ | ||
sealed interface LoxoneAuth { | ||
/** | ||
* No authentication. | ||
*/ | ||
data object None : LoxoneAuth | ||
|
||
/** | ||
* Token based authentication. Can be used both for HTTP and WebSocket. | ||
* @param[authenticator] Token authenticator. | ||
*/ | ||
class Token(val authenticator: LoxoneTokenAuthenticator) : LoxoneAuth | ||
|
||
/** | ||
* Basic authentication. Only suitable for HTTP. | ||
* @param[username] Loxone username. | ||
* @param[password] Loxone password. | ||
*/ | ||
class Basic(val username: String, val password: String) : LoxoneAuth { | ||
constructor(credentials: LoxoneCredentials) : this(credentials.username, credentials.password) | ||
constructor(profile: LoxoneProfile) : this( | ||
requireNotNull(profile.credentials) { "Credentials are required for Basic authentication" } | ||
) | ||
} | ||
|
||
/** | ||
* Returns token authenticator if this authentication is token based. | ||
*/ | ||
val tokenAuthenticator: LoxoneTokenAuthenticator? | ||
get() = when (this) { | ||
is Token -> authenticator | ||
else -> null | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters