-
Notifications
You must be signed in to change notification settings - Fork 3
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
30 changed files
with
373 additions
and
101 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
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,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
function cd_to_source_directory() { | ||
cd `dirname ${0}`/.. | ||
} | ||
|
||
function run_tests() { | ||
python3 -m unittest discover tests -b | ||
} | ||
|
||
cd_to_source_directory | ||
run_tests |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
|
||
from huemon.api.api import Api | ||
from huemon.api.cached_api import CachedApi | ||
from huemon.const import DEFAULT_MAX_CACHE_AGE_SECONDS | ||
|
||
|
||
def create_hue_hub_url(config: dict): | ||
return f"http://{config['ip']}/api/{config['key']}" | ||
|
||
|
||
def create_api(config: dict): | ||
enable_cache = \ | ||
"cache" in config and \ | ||
"enable" in config["cache"] and \ | ||
bool(config["cache"]["enable"]) | ||
|
||
is_cache_age_configured = \ | ||
"cache" in config and \ | ||
"max_age_seconds" in config["cache"] | ||
|
||
max_cache_age_seconds = \ | ||
int(config["cache"]["max_age_seconds"]) if \ | ||
is_cache_age_configured else \ | ||
DEFAULT_MAX_CACHE_AGE_SECONDS | ||
|
||
api = Api(create_hue_hub_url(config)) | ||
|
||
return CachedApi(api, max_cache_age_seconds) if enable_cache else api |
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
Empty file.
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,37 @@ | ||
# Copyright (c) Ely Deckers. | ||
# | ||
# This source code is licensed under the MPL-2.0 license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from functools import reduce | ||
|
||
from huemon.api.api_interface import ApiInterface | ||
from huemon.infrastructure.logger_factory import create_logger | ||
from huemon.util import exit_fail | ||
|
||
LOG = create_logger() | ||
|
||
|
||
def create_name_to_command_mapping(config: dict, api: ApiInterface, plugins: list): | ||
return reduce( | ||
lambda p, c: {**p, c.name(): c(config, api)}, plugins, {}) | ||
|
||
|
||
class CommandHandler: # pylint: disable=too-few-public-methods | ||
def __init__(self, handlers): | ||
self.handlers = handlers | ||
|
||
def available_commands(self): | ||
return list(self.handlers) | ||
|
||
def exec(self, command: str, arguments): | ||
LOG.debug("Running command `%s` (arguments=%s)", command, arguments) | ||
if not command in self.handlers: | ||
exit_fail( | ||
"Received unknown command `%s`, expected one of %s", | ||
command, | ||
self.available_commands()) | ||
|
||
self.handlers[command].exec(arguments) | ||
|
||
LOG.debug("Finished command `%s` (arguments=%s)", command, arguments) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# Copyright (c) Ely Deckers. | ||
# | ||
# This source code is licensed under the MPL-2.0 license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
DEFAULT_MAX_CACHE_AGE_SECONDS = 10 | ||
|
||
EXIT_OK = 0 | ||
EXIT_FAIL = 1 |
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
Empty file.
Oops, something went wrong.