Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41dc77ff4f | ||
|
|
c5cf8edfd6 | ||
|
|
2dca59fa3f | ||
|
|
df95265af0 | ||
|
|
78057939da | ||
|
|
a4a607768a | ||
|
|
a9b2bdb775 | ||
|
|
eee37346ab | ||
|
|
6ee7ce8f70 | ||
|
|
2dfbc31b5d | ||
|
|
ab4997494d | ||
|
|
83b1c85043 | ||
|
|
7526b578ba | ||
|
|
c461640957 | ||
|
|
fd0a0aa0c4 |
No files matched your search
+12
-136
@@ -1,5 +1,17 @@
|
|||||||
# Changelog 
|
# Changelog 
|
||||||
|
|
||||||
|
## [0.7.4] Bugfixes
|
||||||
|
|
||||||
|
- Backend now correctly returns unset alias + description
|
||||||
|
|
||||||
|
## [0.7.1] Bugfixes + Italian!
|
||||||
|
|
||||||
|
- Added support for automations that do not have an `id`
|
||||||
|
- Added Italian
|
||||||
|
- Merged grammar fixes for french
|
||||||
|
- Fixed up strange centering styling bug
|
||||||
|
- Replaced more non-multilingual texts with multilingual text
|
||||||
|
|
||||||
## [0.7.0] Configuration Menu / Light Mode / Lang Support
|
## [0.7.0] Configuration Menu / Light Mode / Lang Support
|
||||||
|
|
||||||
- Added configuration menu
|
- Added configuration menu
|
||||||
@@ -17,11 +29,6 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## [0.6.2] - Patches
|
|
||||||
|
|
||||||
- Attempting to increasing websocket file limit
|
|
||||||
- Support for all !include directives
|
|
||||||
|
|
||||||
## [0.6.1] - v0.6.0 Split Config Support & Better Error handling!
|
## [0.6.1] - v0.6.0 Split Config Support & Better Error handling!
|
||||||
|
|
||||||
- Added visual support for split config (this was a heavy refactor!)
|
- Added visual support for split config (this was a heavy refactor!)
|
||||||
@@ -37,11 +44,6 @@
|
|||||||
- Better global error capture
|
- Better global error capture
|
||||||

|

|
||||||
|
|
||||||
## [0.5.3] - Bug Fixes
|
|
||||||
|
|
||||||
- Redirecting `/` to `/web` to resolve container install strangeness reported in https://github.com/asosnovsky/Shortumation/issues/125
|
|
||||||
- Fixed missing flag that caused the automation to explode in https://github.com/asosnovsky/Shortumation/issues/124
|
|
||||||
|
|
||||||
## [0.5.2] - Better Controls
|
## [0.5.2] - Better Controls
|
||||||
|
|
||||||
- Add automation trigger
|
- Add automation trigger
|
||||||
@@ -62,11 +64,6 @@
|
|||||||
|
|
||||||
- Websockets now live-refresh when updates occur
|
- Websockets now live-refresh when updates occur
|
||||||
|
|
||||||
## [0.4.0] - Depedency update
|
|
||||||
|
|
||||||
- Core dependency updates
|
|
||||||
- Python port is now dynamically set
|
|
||||||
|
|
||||||
## [0.3.4] - Condition/Trigger Editor Upgrades!
|
## [0.3.4] - Condition/Trigger Editor Upgrades!
|
||||||
|
|
||||||
- Many condition editor fixes
|
- Many condition editor fixes
|
||||||
@@ -83,19 +80,6 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## [0.3.2] - Fixed Addon Image for arm-based devices
|
|
||||||
|
|
||||||
- Using hypercon instead of uvicorn (this losses the rust dependency which makes it easier to install on arm)
|
|
||||||
- Pre-building web assets outside of docker (this takes the image size down and speeds up instaltion of addon)
|
|
||||||
- Updated build scripts to actually fail installation when build/prep steps fail
|
|
||||||
- Ensured that builds for all architecture run successfully
|
|
||||||
- Re-worked github actions (quicker test phases)
|
|
||||||
|
|
||||||
## [0.3.1] - Increased Pagination + Restricted Repeat Node
|
|
||||||
|
|
||||||
- Increased pagination to display up to 10,000 autos for now
|
|
||||||
- Repeat node now has types
|
|
||||||
|
|
||||||
## [0.3.0] - Complete Refactor of Graphs
|
## [0.3.0] - Complete Refactor of Graphs
|
||||||
|
|
||||||
- Added visual support for
|
- Added visual support for
|
||||||
@@ -114,113 +98,5 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## [0.1.22] - Many Visual improvements
|
|
||||||
|
|
||||||
- Deprecated several custom components in favor of mui.com
|
|
||||||
- Device Editor now has support for 99% of diplay types
|
|
||||||
- Condition Device is implemented
|
|
||||||
- Improved naming autogen for trigger & choose
|
|
||||||
|
|
||||||
## [0.1.21] - Service Editor
|
|
||||||
|
|
||||||
- first version of service editor
|
|
||||||
- reloading automations on save
|
|
||||||
|
|
||||||
## [0.1.20] - UI Bugfixes
|
|
||||||
|
|
||||||
- Using MUI elements for input time
|
|
||||||
- Added delay action / wait_on_triggers action
|
|
||||||
- Added enabled/disabled flag in node editor
|
|
||||||
- Optional flip vertical during desktop mode
|
|
||||||
- Fixed up modal clipping
|
|
||||||
|
|
||||||
## [0.1.19] - Vertical mobile mode
|
|
||||||
|
|
||||||
- in mobile mode we draw the graphs vertically now
|
|
||||||
|
|
||||||
## [0.1.17] - Websockets
|
|
||||||
|
|
||||||
- Connected to HA main websocket -- now we retrieve real-time information about
|
|
||||||
|
|
||||||
- Device names
|
|
||||||
- Entity names/ids
|
|
||||||
|
|
||||||
- Autocomplete for devices and entities
|
|
||||||
|
|
||||||
## [0.1.14] - Material UI + Autocomplete
|
|
||||||
|
|
||||||
- Brought some Material UI elements for input and text
|
|
||||||
- Autocomplete for tags
|
|
||||||
- Using 'id' as alias for trigger (as it seems to break HA otherwise)
|
|
||||||
- Not using 'alias' for conditions, always auto-generating it (again, this used to break HA)
|
|
||||||
- Added missing `data` object to service-actions
|
|
||||||
|
|
||||||
## [0.1.13] - YAML
|
|
||||||
|
|
||||||
- Better YAML
|
|
||||||
- Rewrote yaml parser/loader to use pyyaml and safe mode
|
|
||||||
- Cleaned up description vs alias
|
|
||||||
|
|
||||||
## [0.1.12] - Less Intense Error Messages
|
|
||||||
|
|
||||||
- Added more node-based errors (this way it's easier to see where validations failed)
|
|
||||||
- Made the validators less strict in order to capture more edge cases that HA supports
|
|
||||||
- Nicer auto-generated descriptions for some trigger nodes
|
|
||||||
|
|
||||||
## [0.1.10] - More Bug Fixes
|
|
||||||
|
|
||||||
- Allowing null or undefined values for metadata fields
|
|
||||||
- Trigger.platform==time will now have the .at property better supported
|
|
||||||
|
|
||||||
## [0.1.9] - Fixed up invalid types for various triggers
|
|
||||||
|
|
||||||
- Some triggers had invalid types and were causing a false-positive validation
|
|
||||||
|
|
||||||
## [0.1.8] - Support for Malformed Automations
|
|
||||||
|
|
||||||
- API will no longer error out on missing values or invalid lists
|
|
||||||
- Frontend has support for displaying bad automations
|
|
||||||
|
|
||||||
## [0.1.6] - Mobile Mode
|
|
||||||
|
|
||||||
- Improved mobile mode
|
|
||||||
- Fixed up arrow styles due to typos
|
|
||||||
- Added selection color
|
|
||||||
|
|
||||||
## [0.1.2] - Docker Hub Images
|
|
||||||
|
|
||||||
- Publishing images to docker hub is now stable
|
|
||||||
|
|
||||||
## [0.0.15] - Publish to dockerhub
|
|
||||||
|
|
||||||
- Publishing images to docker hub
|
|
||||||
|
|
||||||
## [0.0.14] - Using vanila ha yaml
|
|
||||||
|
|
||||||
- Supporing vanilla out of the box HA yaml as oppose to parsing them (no more $smType)
|
|
||||||
- Conditions have now a more a explicit node
|
|
||||||
|
|
||||||
## [0.0.13] - Better Styling with react-flow
|
|
||||||
|
|
||||||
- Fixed up styling (using react-flow)
|
|
||||||
- cleaned up some button styles
|
|
||||||
|
|
||||||
## [0.0.12] - Tags
|
|
||||||
|
|
||||||
- Added tag management system for automations
|
|
||||||
|
|
||||||
## [0.0.11] - Zoom
|
|
||||||
|
|
||||||
- Added lazy saving
|
|
||||||
|
|
||||||
## [0.0.10] - Zoom
|
|
||||||
|
|
||||||
- Introducing Zoom!
|
|
||||||
|
|
||||||
## [0.0.9] - First Working Version
|
|
||||||
|
|
||||||
- Instalable verion via github
|
|
||||||
- Initial POC done
|
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
@@ -11,7 +11,7 @@ from src.hass_config.loader import HassConfig
|
|||||||
def make_automation_router(hass_config: HassConfig) -> APIRouter:
|
def make_automation_router(hass_config: HassConfig) -> APIRouter:
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/list")
|
@router.post("/list", response_model_exclude_unset=True, response_model_exclude_none=True)
|
||||||
def list_autos(body: ListParams) -> ListData[ExtenededAutomation]:
|
def list_autos(body: ListParams) -> ListData[ExtenededAutomation]:
|
||||||
automations = AutomationManager(hass_config)
|
automations = AutomationManager(hass_config)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ class FailedDeletion(AutomationLoaderException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidPackage(AutomationLoaderException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DBError(Exception):
|
class DBError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from src.yaml_serializer import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from ..hass_config.loader import HassConfig
|
from ..hass_config.loader import HassConfig
|
||||||
from .errors import InvalidAutomationFile
|
from .errors import InvalidAutomationFile, InvalidPackage
|
||||||
from .tags import TagManager
|
from .tags import TagManager
|
||||||
from .types import (
|
from .types import (
|
||||||
AutomationExtractedIter,
|
AutomationExtractedIter,
|
||||||
@@ -46,7 +46,9 @@ def load_and_iter_automations(
|
|||||||
elif isinstance(ref, InlineAutomation):
|
elif isinstance(ref, InlineAutomation):
|
||||||
yield from load_automation_inline_ref(hass_config.root_path, tag_manager, ref)
|
yield from load_automation_inline_ref(hass_config.root_path, tag_manager, ref)
|
||||||
else:
|
else:
|
||||||
raise AssertionError(f"ref has an invalid type of {type(ref)} = {ref}")
|
raise logger.error(
|
||||||
|
AssertionError(f"ref has an invalid type of {type(ref)} = {ref}")
|
||||||
|
)
|
||||||
except InvalidAutomationFile as e:
|
except InvalidAutomationFile as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
@@ -56,12 +58,17 @@ def extract_automation_refs(
|
|||||||
) -> AutomationExtractedIter:
|
) -> AutomationExtractedIter:
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
for ref in chain(
|
for ref in extract_automation_root_refs(hass_config):
|
||||||
extract_automation_root_refs(hass_config), extract_automation_package_refs(hass_config)
|
|
||||||
):
|
|
||||||
found = True
|
found = True
|
||||||
yield ref
|
yield ref
|
||||||
|
|
||||||
|
try:
|
||||||
|
for ref in extract_automation_package_refs(hass_config):
|
||||||
|
found = True
|
||||||
|
yield ref
|
||||||
|
except InvalidPackage as err:
|
||||||
|
logger.fatal(err)
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
yield IncludedAutoamtion([""], IncludedYaml(hass_config.root_path / "automations.yaml"))
|
yield IncludedAutoamtion([""], IncludedYaml(hass_config.root_path / "automations.yaml"))
|
||||||
|
|
||||||
@@ -80,7 +87,7 @@ def extract_automation_root_refs(
|
|||||||
source_file=hass_config.get_configuration_path(),
|
source_file=hass_config.get_configuration_path(),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning(f"found an invalid type in {key}!")
|
logger.error(f"found an invalid type in {key}!")
|
||||||
|
|
||||||
|
|
||||||
def extract_automation_package_refs(hass_config: HassConfig) -> AutomationExtractedIter:
|
def extract_automation_package_refs(hass_config: HassConfig) -> AutomationExtractedIter:
|
||||||
@@ -93,7 +100,7 @@ def extract_automation_package_refs(hass_config: HassConfig) -> AutomationExtrac
|
|||||||
packages,
|
packages,
|
||||||
)
|
)
|
||||||
elif isinstance(packages_config, IncludedYamlDirList):
|
elif isinstance(packages_config, IncludedYamlDirList):
|
||||||
raise AssertionError("cannot configure packages with 'included_dir_list' directive")
|
raise InvalidPackage("cannot configure packages with 'included_dir_list' directive")
|
||||||
elif isinstance(packages_config, IncludedYamlDirNamed):
|
elif isinstance(packages_config, IncludedYamlDirNamed):
|
||||||
packages = packages_config.to_normalized_json(use_path_as_keys=True)
|
packages = packages_config.to_normalized_json(use_path_as_keys=True)
|
||||||
for package_path, package in packages.items():
|
for package_path, package in packages.items():
|
||||||
@@ -109,7 +116,7 @@ def extract_automation_package_refs(hass_config: HassConfig) -> AutomationExtrac
|
|||||||
package_set,
|
package_set,
|
||||||
) in iter(packages_config):
|
) in iter(packages_config):
|
||||||
if not isinstance(package_set, dict):
|
if not isinstance(package_set, dict):
|
||||||
raise AssertionError(
|
raise InvalidPackage(
|
||||||
f"expected {pacakge_set_path} to be a dictionary but got {type(package_set)}"
|
f"expected {pacakge_set_path} to be a dictionary but got {type(package_set)}"
|
||||||
)
|
)
|
||||||
yield from extract_automation_inline_package_refs(
|
yield from extract_automation_inline_package_refs(
|
||||||
@@ -124,7 +131,7 @@ def extract_automation_package_refs(hass_config: HassConfig) -> AutomationExtrac
|
|||||||
packages_config,
|
packages_config,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise AssertionError("configurations.homeassistant.packages must be a dictionary!")
|
raise InvalidPackage("configurations.homeassistant.packages must be a dictionary!")
|
||||||
|
|
||||||
|
|
||||||
def extract_automation_inline_package_refs(
|
def extract_automation_inline_package_refs(
|
||||||
@@ -134,44 +141,47 @@ def extract_automation_inline_package_refs(
|
|||||||
ignore_package_name=False,
|
ignore_package_name=False,
|
||||||
) -> AutomationExtractedIter:
|
) -> AutomationExtractedIter:
|
||||||
for package_name, package_data in packages_config.items():
|
for package_name, package_data in packages_config.items():
|
||||||
if isinstance(package_data, IncludedYaml):
|
try:
|
||||||
package_mapping = package_data.to_normalized_json()
|
if isinstance(package_data, IncludedYaml):
|
||||||
yield from extract_automation_from_package(
|
package_mapping = package_data.to_normalized_json()
|
||||||
package_data=package_mapping,
|
|
||||||
package_name=package_name,
|
|
||||||
source_file=source_file,
|
|
||||||
prefix_config_keys=prefix_config_keys,
|
|
||||||
ignore_package_name=ignore_package_name,
|
|
||||||
)
|
|
||||||
elif isinstance(package_data, IncludedYamlDirList):
|
|
||||||
raise NotImplementedError(package_data)
|
|
||||||
elif isinstance(package_data, IncludedYamlDirNamed):
|
|
||||||
for package_key_path in package_data.to_normalized_json(True).keys():
|
|
||||||
if package_key_path.stem == "automation":
|
|
||||||
yield IncludedAutoamtion(
|
|
||||||
configuration_key=[package_name], ref=IncludedYaml(package_key_path)
|
|
||||||
)
|
|
||||||
elif isinstance(package_data, IncludedYamlDirMergedNamed):
|
|
||||||
for data_path, data_set in iter(package_data):
|
|
||||||
yield from extract_automation_from_package(
|
yield from extract_automation_from_package(
|
||||||
|
package_data=package_mapping,
|
||||||
package_name=package_name,
|
package_name=package_name,
|
||||||
package_data=data_set,
|
source_file=source_file,
|
||||||
source_file=data_path,
|
prefix_config_keys=prefix_config_keys,
|
||||||
prefix_config_keys=[],
|
ignore_package_name=ignore_package_name,
|
||||||
ignore_package_name=True,
|
|
||||||
)
|
)
|
||||||
elif isinstance(package_data, dict):
|
elif isinstance(package_data, IncludedYamlDirList):
|
||||||
yield from extract_automation_from_package(
|
raise NotImplementedError(package_data)
|
||||||
package_data=package_data,
|
elif isinstance(package_data, IncludedYamlDirNamed):
|
||||||
package_name=package_name,
|
for package_key_path in package_data.to_normalized_json(True).keys():
|
||||||
source_file=source_file,
|
if package_key_path.stem == "automation":
|
||||||
prefix_config_keys=prefix_config_keys,
|
yield IncludedAutoamtion(
|
||||||
ignore_package_name=ignore_package_name,
|
configuration_key=[package_name], ref=IncludedYaml(package_key_path)
|
||||||
)
|
)
|
||||||
else:
|
elif isinstance(package_data, IncludedYamlDirMergedNamed):
|
||||||
raise AssertionError(
|
for data_path, data_set in iter(package_data):
|
||||||
f"configurations.homeassistant.packages[{package_name}] must be a dictionary!"
|
yield from extract_automation_from_package(
|
||||||
)
|
package_name=package_name,
|
||||||
|
package_data=data_set,
|
||||||
|
source_file=data_path,
|
||||||
|
prefix_config_keys=[],
|
||||||
|
ignore_package_name=True,
|
||||||
|
)
|
||||||
|
elif isinstance(package_data, dict):
|
||||||
|
yield from extract_automation_from_package(
|
||||||
|
package_data=package_data,
|
||||||
|
package_name=package_name,
|
||||||
|
source_file=source_file,
|
||||||
|
prefix_config_keys=prefix_config_keys,
|
||||||
|
ignore_package_name=ignore_package_name,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise InvalidPackage(
|
||||||
|
f"configurations.homeassistant.packages[{package_name}] must be a dictionary!"
|
||||||
|
)
|
||||||
|
except Exception as err:
|
||||||
|
logger.error(err)
|
||||||
|
|
||||||
|
|
||||||
def extract_automation_from_package(
|
def extract_automation_from_package(
|
||||||
@@ -330,6 +340,8 @@ def load_automation_path(
|
|||||||
def clean_automation(auto_raw: dict):
|
def clean_automation(auto_raw: dict):
|
||||||
return {
|
return {
|
||||||
**auto_raw,
|
**auto_raw,
|
||||||
|
"alias": auto_raw.get("alias", "") or "",
|
||||||
|
"description": auto_raw.get("description", "") or "",
|
||||||
"condition": ifempty_or_null_then_list(load_conditions(auto_raw.get("condition", []))),
|
"condition": ifempty_or_null_then_list(load_conditions(auto_raw.get("condition", []))),
|
||||||
"action": ifempty_or_null_then_list(load_conditions(auto_raw.get("action", []))),
|
"action": ifempty_or_null_then_list(load_conditions(auto_raw.get("action", []))),
|
||||||
"trigger": ifempty_or_null_then_list(normalize_obj(auto_raw.get("trigger", []))),
|
"trigger": ifempty_or_null_then_list(normalize_obj(auto_raw.get("trigger", []))),
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ AutomationExtractedIter = Iterator[ExtractedAutomation]
|
|||||||
|
|
||||||
class BaseAutomation(BaseModel):
|
class BaseAutomation(BaseModel):
|
||||||
id: Optional[str]
|
id: Optional[str]
|
||||||
alias: Optional[str] = None
|
alias: str = ""
|
||||||
description: Optional[str] = None
|
description: str = ""
|
||||||
trigger_variables: Optional[dict[str, Union[str, int, bool, float]]] = None
|
trigger_variables: Optional[dict[str, Union[str, int, bool, float]]] = None
|
||||||
mode: str = "single"
|
mode: str = "single"
|
||||||
trigger: list[dict] = []
|
trigger: list[dict] = []
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Iterator, NamedTuple, Tuple, Union
|
from typing import Iterator, NamedTuple, Tuple
|
||||||
|
|
||||||
from yaml.nodes import Node
|
from yaml.nodes import Node
|
||||||
|
|
||||||
|
from src.logger import get_logger
|
||||||
|
|
||||||
from .manager import YamlManager
|
from .manager import YamlManager
|
||||||
|
|
||||||
dump_yaml = YamlManager.dump_yaml
|
dump_yaml = YamlManager.dump_yaml
|
||||||
load_yaml = YamlManager.load_yaml
|
load_yaml = YamlManager.load_yaml
|
||||||
|
|
||||||
|
logger = get_logger(__file__)
|
||||||
|
|
||||||
|
|
||||||
def load_dir_yaml(folder_or_file: Path) -> Iterator[Tuple[Path, dict | list]]:
|
def load_dir_yaml(folder_or_file: Path) -> Iterator[Tuple[Path, dict | list]]:
|
||||||
if folder_or_file.is_dir():
|
if folder_or_file.is_dir():
|
||||||
for file in folder_or_file.iterdir():
|
for file in folder_or_file.iterdir():
|
||||||
yield from load_dir_yaml(file)
|
yield from load_dir_yaml(file)
|
||||||
else:
|
else:
|
||||||
with folder_or_file.open("r") as fp:
|
if folder_or_file.suffix.lower() == ".yaml":
|
||||||
yield folder_or_file, load_yaml(fp, root_path=folder_or_file.parent)
|
with folder_or_file.open("r") as fp:
|
||||||
|
yield folder_or_file, load_yaml(fp, root_path=folder_or_file.parent)
|
||||||
|
else:
|
||||||
|
logger.info(f"Ignoring the file {folder_or_file}")
|
||||||
|
|
||||||
|
|
||||||
@YamlManager.as_constructor("!include")
|
@YamlManager.as_constructor("!include")
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# all the packages!
|
||||||
|
|
||||||
|
This is really cool :)
|
||||||
|
|
||||||
|
- A list item!
|
||||||
|
|
||||||
|
<<more thisngs!>>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# all the packages!
|
||||||
|
|
||||||
|
This is really cool :)
|
||||||
|
|
||||||
|
- A list item!
|
||||||
|
|
||||||
|
<<more thisngs!>>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# all the packages!
|
||||||
|
|
||||||
|
This is really cool :)
|
||||||
|
|
||||||
|
- A list item!
|
||||||
|
|
||||||
|
<<more thisngs!>>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# all the packages!
|
||||||
|
|
||||||
|
This is really cool :)
|
||||||
|
|
||||||
|
- A list item!
|
||||||
|
|
||||||
|
<<more thisngs!>>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
- alias: UI 1
|
||||||
|
description: Example
|
||||||
|
mode: single
|
||||||
|
trigger:
|
||||||
|
- platform: homeassistant
|
||||||
|
event: start
|
||||||
|
condition: []
|
||||||
|
action:
|
||||||
|
- service: counter.increment
|
||||||
|
data: {}
|
||||||
|
target:
|
||||||
|
entity_id: counter.up_times
|
||||||
|
- alias: UI 2
|
||||||
|
description: ""
|
||||||
|
trigger:
|
||||||
|
- platform: sun
|
||||||
|
event: sunrise
|
||||||
|
offset: 0
|
||||||
|
condition: []
|
||||||
|
action: []
|
||||||
|
mode: single
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
homeassistant:
|
||||||
|
packages: !include_dir_named integrations
|
||||||
Whitespace-only changes.
@@ -0,0 +1 @@
|
|||||||
|
automation: !include ../automations.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
media_player: !include_dir_list ../entities/media_players
|
||||||
@@ -249,7 +249,7 @@ class automation_update_tests(BaseTestCase):
|
|||||||
)
|
)
|
||||||
autos = resp.json()["data"]
|
autos = resp.json()["data"]
|
||||||
self.assertEqual(resp.json()["totalItems"], self.test_params["total"])
|
self.assertEqual(resp.json()["totalItems"], self.test_params["total"])
|
||||||
self.assertNotIn("i am new", set([a["id"] for a in autos]))
|
self.assertNotIn("i am new", set([a.get("id", "") for a in autos]))
|
||||||
resp = self.client.post(
|
resp = self.client.post(
|
||||||
"/automations/item",
|
"/automations/item",
|
||||||
json=Automation(
|
json=Automation(
|
||||||
@@ -262,7 +262,7 @@ class automation_update_tests(BaseTestCase):
|
|||||||
)
|
)
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
self.assertEqual(data["totalItems"], self.test_params["total"] + 1)
|
self.assertEqual(data["totalItems"], self.test_params["total"] + 1)
|
||||||
self.assertIn("i am new", set([a["id"] for a in data["data"]]))
|
self.assertIn("i am new", set([a.get("id", "") for a in data["data"]]))
|
||||||
|
|
||||||
def test_update_some(self):
|
def test_update_some(self):
|
||||||
resp = self.client.post(
|
resp = self.client.post(
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from src.automations.tags import TagManager
|
|||||||
from src.automations.types import ExtenededAutomation
|
from src.automations.types import ExtenededAutomation
|
||||||
from src.hass_config.loader import HassConfig
|
from src.hass_config.loader import HassConfig
|
||||||
from tests.utils import (
|
from tests.utils import (
|
||||||
|
HA_CONFIG14_EXAMPLE,
|
||||||
HA_CONFIG2_EXAMPLE,
|
HA_CONFIG2_EXAMPLE,
|
||||||
HA_CONFIG3_EXAMPLE,
|
HA_CONFIG3_EXAMPLE,
|
||||||
HA_CONFIG4_EXAMPLE,
|
HA_CONFIG4_EXAMPLE,
|
||||||
@@ -162,6 +163,7 @@ class loader_tests(TestCase):
|
|||||||
(HA_CONFIG11_EXAMPLE, 3),
|
(HA_CONFIG11_EXAMPLE, 3),
|
||||||
(HA_CONFIG12_EXAMPLE, 4),
|
(HA_CONFIG12_EXAMPLE, 4),
|
||||||
(HA_CONFIG13_EXAMPLE, 4),
|
(HA_CONFIG13_EXAMPLE, 4),
|
||||||
|
(HA_CONFIG14_EXAMPLE, 1),
|
||||||
]:
|
]:
|
||||||
with self.subTest(config_name=ha_path.name, expected=expected):
|
with self.subTest(config_name=ha_path.name, expected=expected):
|
||||||
hass_config = HassConfig(ha_path)
|
hass_config = HassConfig(ha_path)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ HA_CONFIG10_EXAMPLE = SAMPLES_FOLDER / "config-10"
|
|||||||
HA_CONFIG11_EXAMPLE = SAMPLES_FOLDER / "config-11"
|
HA_CONFIG11_EXAMPLE = SAMPLES_FOLDER / "config-11"
|
||||||
HA_CONFIG12_EXAMPLE = SAMPLES_FOLDER / "config-12"
|
HA_CONFIG12_EXAMPLE = SAMPLES_FOLDER / "config-12"
|
||||||
HA_CONFIG13_EXAMPLE = SAMPLES_FOLDER / "config-13"
|
HA_CONFIG13_EXAMPLE = SAMPLES_FOLDER / "config-13"
|
||||||
|
HA_CONFIG14_EXAMPLE = SAMPLES_FOLDER / "config-14"
|
||||||
|
|
||||||
|
|
||||||
def get_example_automation_loader(
|
def get_example_automation_loader(
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: Shortumation
|
name: Shortumation
|
||||||
version: v0.7.0
|
version: v0.7.4
|
||||||
slug: shortumation
|
slug: shortumation
|
||||||
image: "asosnovsky/shortumation-{arch}"
|
image: "asosnovsky/shortumation-{arch}"
|
||||||
url: "https://github.com/asosnovsky/Shortumation"
|
url: "https://github.com/asosnovsky/Shortumation"
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import "./App.css";
|
import "./App.css";
|
||||||
import { Routes, Route, BrowserRouter } from "react-router-dom";
|
import { Routes, Route, BrowserRouter } from "react-router-dom";
|
||||||
import { AutomationRoute } from "routes/automation";
|
import { AutomationRoute } from "routes/automation";
|
||||||
import { useConnectedApiService } from "apiService";
|
import { useConnectedApiService } from "services/api";
|
||||||
import { ErrorBoundary } from "components/ErrorBoundary";
|
import { ErrorBoundary } from "components/ErrorBoundary";
|
||||||
import { CookiesProvider } from "react-cookie";
|
import { CookiesProvider } from "react-cookie";
|
||||||
import { Page } from "components/Page";
|
import { Page } from "components/Page";
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { AddIcon, TrashIcon } from "components/Icons";
|
|||||||
import InputAutoText from "components/Inputs/InputAutoText";
|
import InputAutoText from "components/Inputs/InputAutoText";
|
||||||
import { TagDB } from "components/AutomationManager/TagDB";
|
import { TagDB } from "components/AutomationManager/TagDB";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export interface AutoInfoBoxProps {
|
export interface AutoInfoBoxProps {
|
||||||
metadata: AutomationMetadata & Partial<AutomationShortumationMetadata>;
|
metadata: AutomationMetadata & Partial<AutomationShortumationMetadata>;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
import { AutomationNode, AutomationNodeMapping } from "types/automations";
|
import { AutomationNode, AutomationNodeMapping } from "types/automations";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import { CollectionNodeElement } from "components/DAGGraph/nodes/CollectionNode/CollectionNodeElement";
|
import { CollectionNodeElement } from "components/DAGGraph/nodes/CollectionNode/CollectionNodeElement";
|
||||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||||
import { Size } from "components/DAGGraph/elements/types";
|
import { Size } from "components/DAGGraph/elements/types";
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import { MiniFailure } from "types/validators/helper";
|
|||||||
|
|
||||||
import { AutoInfoBox } from "./AutoInfoBox";
|
import { AutoInfoBox } from "./AutoInfoBox";
|
||||||
import { useAutomatioEditorState, EditorData } from "./state";
|
import { useAutomatioEditorState, EditorData } from "./state";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { Alert } from "@mui/material";
|
import { Alert } from "@mui/material";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { HassEntities } from "home-assistant-js-websocket";
|
import { HassEntities } from "home-assistant-js-websocket";
|
||||||
import { LangStore, useLang } from "lang";
|
import { LangStore, useLang } from "services/lang";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { AutomationData, BareAutomationData } from "types/automations";
|
import { AutomationData, BareAutomationData } from "types/automations";
|
||||||
import { defaultAutomation } from "utils/defaults";
|
import { defaultAutomation } from "utils/defaults";
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from "./state";
|
} from "./state";
|
||||||
import Alert from "@mui/material/Alert";
|
import Alert from "@mui/material/Alert";
|
||||||
import { useConfirm } from "material-ui-confirm";
|
import { useConfirm } from "material-ui-confirm";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
export type AutomationManagerLoadedProps = UseAutomationManagerStateArgs & {
|
||||||
onAutomationDelete: (aid: string, eid: string) => void;
|
onAutomationDelete: (aid: string, eid: string) => void;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { useAutomationDB } from "./automationDB";
|
|||||||
import { useConfirm } from "material-ui-confirm";
|
import { useConfirm } from "material-ui-confirm";
|
||||||
import { AutomationManagerAutoUpdatable } from "../types";
|
import { AutomationManagerAutoUpdatable } from "../types";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type UseAutomationManagerStateArgs = {
|
export type UseAutomationManagerStateArgs = {
|
||||||
configAutomations: AutomationData[];
|
configAutomations: AutomationData[];
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { Button } from "components/Inputs/Buttons/Button";
|
|||||||
import InputAutoText from "components/Inputs/InputAutoText";
|
import InputAutoText from "components/Inputs/InputAutoText";
|
||||||
|
|
||||||
import { TagDB } from "../TagDB";
|
import { TagDB } from "../TagDB";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type TagsProps = {
|
export type TagsProps = {
|
||||||
automationId: string;
|
automationId: string;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { ButtonIcon } from "components/Icons/ButtonIcons";
|
|||||||
import { AutomationManagerAuto } from "../types";
|
import { AutomationManagerAuto } from "../types";
|
||||||
import { Tags } from "./Tags";
|
import { Tags } from "./Tags";
|
||||||
import { TagDB } from "../TagDB";
|
import { TagDB } from "../TagDB";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type MetadataBoxProps = AutomationManagerAuto & {
|
export type MetadataBoxProps = AutomationManagerAuto & {
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
} from "../types";
|
} from "../types";
|
||||||
import { Button } from "components/Inputs/Buttons/Button";
|
import { Button } from "components/Inputs/Buttons/Button";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type AutomationManagerSidebarProps = {
|
export type AutomationManagerSidebarProps = {
|
||||||
tagsDB: TagDB;
|
tagsDB: TagDB;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { makeStory } from "devUtils";
|
import { makeStory } from "devUtils";
|
||||||
import { useMockApiService } from "apiService";
|
import { useMockApiService } from "services/api";
|
||||||
import { AutomationManager } from ".";
|
import { AutomationManager } from ".";
|
||||||
import {
|
import {
|
||||||
MockHAEntitiesProps,
|
MockHAEntitiesProps,
|
||||||
useMockHAEntities,
|
useMockHAEntities,
|
||||||
} from "haService/HAEntities.mock";
|
} from "services/ha/HAEntities.mock";
|
||||||
import { AutomationData } from "types/automations";
|
import { AutomationData } from "types/automations";
|
||||||
import { createMockAuto } from "utils/mocks";
|
import { createMockAuto } from "utils/mocks";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@@ -109,7 +109,7 @@ export const MissingAutoInConfig = make({
|
|||||||
entity_id: `automation.${auto1.id}`,
|
entity_id: `automation.${auto1.id}`,
|
||||||
attributes: {
|
attributes: {
|
||||||
id: auto1.id,
|
id: auto1.id,
|
||||||
friendly_name: auto1.alias,
|
friendly_name: auto1.alias ?? auto1.id ?? "",
|
||||||
},
|
},
|
||||||
context: { id: "", parent_id: null, user_id: null },
|
context: { id: "", parent_id: null, user_id: null },
|
||||||
last_changed: "",
|
last_changed: "",
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { FC, useEffect, useRef, useState } from "react";
|
|||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
import Skeleton from "@mui/material/Skeleton";
|
import Skeleton from "@mui/material/Skeleton";
|
||||||
|
|
||||||
import { ApiService } from "apiService/core";
|
import { ApiService } from "services/api/core";
|
||||||
import { HAEntitiesState } from "haService/HAEntities";
|
import { HAEntitiesState } from "services/ha/HAEntities";
|
||||||
import { AutomationManagerLoaded } from "./Loaded";
|
import { AutomationManagerLoaded } from "./Loaded";
|
||||||
import { Alert } from "@mui/material";
|
import { Alert } from "@mui/material";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
@@ -14,8 +14,8 @@ import { getFailures } from "types/validators/helper";
|
|||||||
import * as av from "types/validators/autmation";
|
import * as av from "types/validators/autmation";
|
||||||
import { useConfirm } from "material-ui-confirm";
|
import { useConfirm } from "material-ui-confirm";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { APIResponse } from "apiService/types";
|
import { APIResponse } from "services/api/types";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type AutomationManagerProps = {
|
export type AutomationManagerProps = {
|
||||||
onAutomationStateChange: (eid: string, on: boolean) => Promise<any>;
|
onAutomationStateChange: (eid: string, on: boolean) => Promise<any>;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Alert from "@mui/material/Alert";
|
import Alert from "@mui/material/Alert";
|
||||||
import Skeleton from "@mui/material/Skeleton";
|
import Skeleton from "@mui/material/Skeleton";
|
||||||
import { ApiService } from "apiService/core";
|
import { ApiService } from "services/api/core";
|
||||||
import { UserProfile } from "apiService/types";
|
import { UserProfile } from "services/api/types";
|
||||||
import { InputList } from "components/Inputs/InputList";
|
import { InputList } from "components/Inputs/InputList";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import { useHAConnection } from "haService/connection";
|
import { useHAConnection } from "services/ha/connection";
|
||||||
import { Button } from "components/Inputs/Buttons/Button";
|
import { Button } from "components/Inputs/Buttons/Button";
|
||||||
import SettingsSuggestOutlinedIcon from "@mui/icons-material/SettingsSuggestOutlined";
|
import SettingsSuggestOutlinedIcon from "@mui/icons-material/SettingsSuggestOutlined";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
import { Modal } from "components/Modal";
|
import { Modal } from "components/Modal";
|
||||||
import { UserProfileEditor, UserProfileProps } from "./UserProfile";
|
import { UserProfileEditor, UserProfileProps } from "./UserProfile";
|
||||||
|
import { useVersioner } from "services/versioner";
|
||||||
|
|
||||||
export type BottomBarProps = UserProfileProps;
|
export type BottomBarProps = UserProfileProps;
|
||||||
export const BottomBar: FC<BottomBarProps> = ({ api }) => {
|
export const BottomBar: FC<BottomBarProps> = ({ api }) => {
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
const ha = useHAConnection();
|
const ha = useHAConnection();
|
||||||
const version = process.env.REACT_APP_BUILD_VERSION ?? "n/a";
|
const versionMgr = useVersioner();
|
||||||
const [isOpen, setOpen] = useState(false);
|
const [isOpen, setOpen] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -31,7 +32,7 @@ export const BottomBar: FC<BottomBarProps> = ({ api }) => {
|
|||||||
🟢
|
🟢
|
||||||
</b>
|
</b>
|
||||||
</span>
|
</span>
|
||||||
<span>version: {version}</span>
|
<span>version: {versionMgr.current}</span>
|
||||||
<Button className="settings" onClick={() => setOpen(!isOpen)}>
|
<Button className="settings" onClick={() => setOpen(!isOpen)}>
|
||||||
<SettingsSuggestOutlinedIcon />
|
<SettingsSuggestOutlinedIcon />
|
||||||
{lang.get("USER_PRERENCES")}
|
{lang.get("USER_PRERENCES")}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import { FC, useState } from "react";
|
|||||||
import { AutomationCondition } from "types/automations/conditions";
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
import { getSubTypeList } from "utils/automations";
|
import { getSubTypeList } from "utils/automations";
|
||||||
import { getConditionDefaultValues } from "utils/defaults";
|
import { getConditionDefaultValues } from "utils/defaults";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { getViewer } from "./viewRender";
|
import { getViewer } from "./viewRender";
|
||||||
import { getEditor } from "./editorRender";
|
import { getEditor } from "./editorRender";
|
||||||
import useWindowSize from "utils/useWindowSize";
|
import useWindowSize from "utils/useWindowSize";
|
||||||
import { ConditionNodeSettings } from "./ConditionNodeSettings";
|
import { ConditionNodeSettings } from "./ConditionNodeSettings";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type ConditionNodeBaseProps = {
|
export type ConditionNodeBaseProps = {
|
||||||
condition: AutomationCondition;
|
condition: AutomationCondition;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
import { genUpdateMethods } from "./nestedUpdater";
|
import { genUpdateMethods } from "./nestedUpdater";
|
||||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { HAService } from "haService";
|
import { HAService } from "services/ha";
|
||||||
import { DeviceEditor } from "components/DeviceEditor";
|
import { DeviceEditor } from "components/DeviceEditor";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
import AddIcon from "@mui/icons-material/Add";
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
@@ -31,7 +31,7 @@ import { prettyName } from "utils/formatting";
|
|||||||
import { InputList } from "components/Inputs/InputList";
|
import { InputList } from "components/Inputs/InputList";
|
||||||
import { Button } from "components/Inputs/Buttons/Button";
|
import { Button } from "components/Inputs/Buttons/Button";
|
||||||
import { RemoveCircle } from "@mui/icons-material";
|
import { RemoveCircle } from "@mui/icons-material";
|
||||||
import { LangStore } from "lang";
|
import { LangStore } from "services/lang";
|
||||||
|
|
||||||
interface Editor<C extends AutomationCondition>
|
interface Editor<C extends AutomationCondition>
|
||||||
extends FC<{
|
extends FC<{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|||||||
import { Page } from "components/Page";
|
import { Page } from "components/Page";
|
||||||
import { DAGGraphBoard } from "components/DAGGraph/board";
|
import { DAGGraphBoard } from "components/DAGGraph/board";
|
||||||
import { useAutomationNodes } from "./index";
|
import { useAutomationNodes } from "./index";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import { AutomationActionData } from "types/automations";
|
import { AutomationActionData } from "types/automations";
|
||||||
import { createUpdaterFromAutomationData } from "../updater";
|
import { createUpdaterFromAutomationData } from "../updater";
|
||||||
import { ModalState } from "../board/types";
|
import { ModalState } from "../board/types";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC, useState, ReactNode } from "react";
|
import { FC, useState, ReactNode } from "react";
|
||||||
import { AutomationSequenceNode } from "types/automations";
|
import { AutomationSequenceNode } from "types/automations";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import { ModalState } from "./board/types";
|
import { ModalState } from "./board/types";
|
||||||
import { createUpdater } from "./updater";
|
import { createUpdater } from "./updater";
|
||||||
import { useAutomationNodes } from "./elements";
|
import { useAutomationNodes } from "./elements";
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { prettyName } from "utils/formatting";
|
|||||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||||
import { useConfirm } from "material-ui-confirm";
|
import { useConfirm } from "material-ui-confirm";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export const CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
export const CollectionNodeElement: FC<PropsWithChildren<CollectionNodeProps>> =
|
||||||
({
|
({
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import InputBoolean from "components/Inputs/Base/InputBoolean";
|
|||||||
import { SpeedDial } from "components/SpeedDial";
|
import { SpeedDial } from "components/SpeedDial";
|
||||||
import { SequenceNodeElementProps } from "./types";
|
import { SequenceNodeElementProps } from "./types";
|
||||||
import { useSequenceNodeColor } from "./util";
|
import { useSequenceNodeColor } from "./util";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export const SequenceNodeElement: FC<
|
export const SequenceNodeElement: FC<
|
||||||
PropsWithChildren<SequenceNodeElementProps>
|
PropsWithChildren<SequenceNodeElementProps>
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
|||||||
import { InputDeviceCapabilties } from "components/Inputs/AutoComplete/InputDeviceCapabilties";
|
import { InputDeviceCapabilties } from "components/Inputs/AutoComplete/InputDeviceCapabilties";
|
||||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||||
import { cleanUpUndefined } from "utils/helpers";
|
import { cleanUpUndefined } from "utils/helpers";
|
||||||
import { DeviceBaseType, DeviceTypeCapability } from "haService/types";
|
import { DeviceBaseType, DeviceTypeCapability } from "services/ha/types";
|
||||||
import { AutomationDeviceState } from "types/automations/common";
|
import { AutomationDeviceState } from "types/automations/common";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type DeviceEditorProps<DBT extends DeviceBaseType> = {
|
export type DeviceEditorProps<DBT extends DeviceBaseType> = {
|
||||||
type: "action" | "condition" | "trigger";
|
type: "action" | "condition" | "trigger";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import "./ButtonIcons.css";
|
|||||||
import Tooltip from "@mui/material/Tooltip";
|
import Tooltip from "@mui/material/Tooltip";
|
||||||
import { FC, ReactNode } from "react";
|
import { FC, ReactNode } from "react";
|
||||||
import IconButton, { IconButtonTypeMap } from "@mui/material/IconButton";
|
import IconButton, { IconButtonTypeMap } from "@mui/material/IconButton";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type ButtonIconProps = {
|
export type ButtonIconProps = {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import {
|
|||||||
InputAutoComplete,
|
InputAutoComplete,
|
||||||
InputAutoCompletePropsBase,
|
InputAutoCompletePropsBase,
|
||||||
} from "./InputAutoComplete";
|
} from "./InputAutoComplete";
|
||||||
import { useHAAreas } from "haService/AreaRegistry";
|
import { useHAAreas } from "services/ha/AreaRegistry";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type InputAreaProps = InputAutoCompletePropsBase & {
|
export type InputAreaProps = InputAutoCompletePropsBase & {
|
||||||
restrictToDomain?: string[];
|
restrictToDomain?: string[];
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import Popper from "@mui/material/Popper";
|
|||||||
import { SearchItem } from "./extras";
|
import { SearchItem } from "./extras";
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type BaseOption<T = {}> = {
|
export type BaseOption<T = {}> = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { useHADeviceRegistry } from "haService";
|
import { useHADeviceRegistry } from "services/ha";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
import {
|
import {
|
||||||
InputAutoComplete,
|
InputAutoComplete,
|
||||||
InputAutoCompletePropsBase,
|
InputAutoCompletePropsBase,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import "./InputDeviceCapabilties.css";
|
import "./InputDeviceCapabilties.css";
|
||||||
import { HaFormSchema } from "haService/types";
|
import { HaFormSchema } from "services/ha/types";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { useRef } from "react";
|
import { useRef } from "react";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { useHAEntities } from "haService/HAEntities";
|
import { useHAEntities } from "services/ha/HAEntities";
|
||||||
import {
|
import {
|
||||||
InputAutoComplete,
|
InputAutoComplete,
|
||||||
InputAutoCompletePropsBase,
|
InputAutoCompletePropsBase,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { useHAServices } from "haService";
|
import { useHAServices } from "services/ha";
|
||||||
import {
|
import {
|
||||||
InputAutoComplete,
|
InputAutoComplete,
|
||||||
InputAutoCompletePropsBase,
|
InputAutoCompletePropsBase,
|
||||||
} from "./InputAutoComplete";
|
} from "./InputAutoComplete";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type InputServiceProps = InputAutoCompletePropsBase & {
|
export type InputServiceProps = InputAutoCompletePropsBase & {
|
||||||
multiple?: false;
|
multiple?: false;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from "utils/time";
|
} from "utils/time";
|
||||||
import { InputEntity } from "./InputEntities";
|
import { InputEntity } from "./InputEntities";
|
||||||
import { InputTime } from "components/Inputs/Base/InputTime";
|
import { InputTime } from "components/Inputs/Base/InputTime";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type InputTimeEntityProps = {
|
export type InputTimeEntityProps = {
|
||||||
value: string;
|
value: string;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, { ReactNode, useState } from "react";
|
import { ReactNode, useState } from "react";
|
||||||
import { useToolTip } from "tooltip/context";
|
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
@@ -22,19 +21,16 @@ export default function InputText({
|
|||||||
label,
|
label,
|
||||||
title,
|
title,
|
||||||
helperText,
|
helperText,
|
||||||
textBoxFor,
|
|
||||||
value = "",
|
value = "",
|
||||||
onChange,
|
onChange,
|
||||||
endAdornment,
|
endAdornment,
|
||||||
onEnter = () => {},
|
onEnter = () => {},
|
||||||
additionalTooltipFilters = {},
|
|
||||||
multiline = false,
|
multiline = false,
|
||||||
maxRows = 4,
|
maxRows = 4,
|
||||||
className,
|
className,
|
||||||
placeholder,
|
placeholder,
|
||||||
required,
|
required,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const tooltip = useToolTip();
|
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
const [isFocused, setIsFocused] = useState(false);
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
@@ -68,17 +64,6 @@ export default function InputText({
|
|||||||
}}
|
}}
|
||||||
onFocus={(e) => {
|
onFocus={(e) => {
|
||||||
setIsFocused(true);
|
setIsFocused(true);
|
||||||
if (textBoxFor) {
|
|
||||||
tooltip.setFocus(
|
|
||||||
e.target.getBoundingClientRect(),
|
|
||||||
{
|
|
||||||
searchObject: textBoxFor,
|
|
||||||
searchText: value,
|
|
||||||
filterObjects: additionalTooltipFilters,
|
|
||||||
},
|
|
||||||
onChange
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from "utils/time";
|
} from "utils/time";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
const fields: Array<keyof AutomationTimeObject> = [
|
const fields: Array<keyof AutomationTimeObject> = [
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import FormHelperText from "@mui/material/FormHelperText";
|
|||||||
import InputAdornment from "@mui/material/InputAdornment";
|
import InputAdornment from "@mui/material/InputAdornment";
|
||||||
import { Save } from "@mui/icons-material";
|
import { Save } from "@mui/icons-material";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export interface Props<T extends {}> {
|
export interface Props<T extends {}> {
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import FormControl from "@mui/material/FormControl";
|
|||||||
import Select from "@mui/material/Select";
|
import Select from "@mui/material/Select";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type Props<T extends string | Object> = {
|
export type Props<T extends string | Object> = {
|
||||||
current?: T;
|
current?: T;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import Autocomplete from "@mui/material/Autocomplete";
|
|||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import Checkbox from "@mui/material/Checkbox";
|
import Checkbox from "@mui/material/Checkbox";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export interface Props<T extends string> {
|
export interface Props<T extends string> {
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import CheckCircleOutlineOutlinedIcon from "@mui/icons-material/CheckCircleOutli
|
|||||||
import ModeEditOutlineOutlinedIcon from "@mui/icons-material/ModeEditOutlineOutlined";
|
import ModeEditOutlineOutlinedIcon from "@mui/icons-material/ModeEditOutlineOutlined";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import Tooltip from "@mui/material/Tooltip";
|
import Tooltip from "@mui/material/Tooltip";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type InputTextViewProps = {
|
export type InputTextViewProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { HAService } from "haService";
|
import { HAService } from "services/ha";
|
||||||
import { HAEntitiesState } from "haService/HAEntities";
|
import { HAEntitiesState } from "services/ha/HAEntities";
|
||||||
import { LangStore } from "lang";
|
import { LangStore } from "services/lang";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { AutomationAction } from "types/automations/actions";
|
import { AutomationAction } from "types/automations/actions";
|
||||||
import { AutomationCondition } from "types/automations/conditions";
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { Button } from "components/Inputs/Buttons/Button";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import AddIcon from "@mui/icons-material/Add";
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
import { InputTimeEntity } from "components/Inputs/AutoComplete/InputTimeEntity";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
export const TriggerTime: OptionManager<AutomationTriggerTime> = {
|
||||||
defaultState: () => ({
|
defaultState: () => ({
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import {
|
|||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import InputText from "components/Inputs/Base/InputText";
|
import InputText from "components/Inputs/Base/InputText";
|
||||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import { Generic } from "./Generic";
|
import { Generic } from "./Generic";
|
||||||
import { getNodeTypeAndValidate } from "utils/automations";
|
import { getNodeTypeAndValidate } from "utils/automations";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
type UseState = <S>(s: S) => [S, Dispatch<SetStateAction<S>>];
|
type UseState = <S>(s: S) => [S, Dispatch<SetStateAction<S>>];
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Button } from "components/Inputs/Buttons/Button";
|
|||||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||||
import { useConfirm } from "material-ui-confirm";
|
import { useConfirm } from "material-ui-confirm";
|
||||||
import { getNodeSubTypeDescription } from "./utils";
|
import { getNodeSubTypeDescription } from "./utils";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export interface NodeEditorProps {
|
export interface NodeEditorProps {
|
||||||
node: AutomationNode;
|
node: AutomationNode;
|
||||||
|
|||||||
@@ -10,23 +10,28 @@ import {
|
|||||||
import { BottomBar } from "components/BottomBar";
|
import { BottomBar } from "components/BottomBar";
|
||||||
import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack";
|
import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import { useHAConnection } from "haService/connection";
|
import { useHAConnection } from "services/ha/connection";
|
||||||
import { ConfirmProvider } from "material-ui-confirm";
|
import { ConfirmProvider } from "material-ui-confirm";
|
||||||
import { Color } from "@mui/material";
|
import { Color, Skeleton, Theme } from "@mui/material";
|
||||||
import useWindowSize from "utils/useWindowSize";
|
import useWindowSize from "utils/useWindowSize";
|
||||||
import { ApiService } from "apiService/core";
|
import { ApiService } from "services/api/core";
|
||||||
import { ApiStateProvider, useMockApiService } from "apiService";
|
import { ApiStateProvider, useMockApiService } from "services/api";
|
||||||
|
import { LangProvider, LangStore, useLang } from "services/lang";
|
||||||
|
|
||||||
export type PageProps = PropsWithChildren<{
|
export type PageProps = PropsWithChildren<{
|
||||||
api: ApiService;
|
api: ApiService;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const InternalPage: FC<PageProps> = ({ children, api }) => {
|
export const BareInternalPage: FC<
|
||||||
|
PageProps & {
|
||||||
|
isMobile: boolean;
|
||||||
|
theme: Theme;
|
||||||
|
lang: LangStore;
|
||||||
|
}
|
||||||
|
> = ({ children, api, isMobile, theme, lang }) => {
|
||||||
const conn = useHAConnection();
|
const conn = useHAConnection();
|
||||||
const theme = useTheme();
|
|
||||||
const snackbar = useSnackbar();
|
const snackbar = useSnackbar();
|
||||||
const snackbarKeyHAConKey = useRef<SnackbarKey | null>(null);
|
const snackbarKeyHAConKey = useRef<SnackbarKey | null>(null);
|
||||||
const { isMobile } = useWindowSize();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (conn.status === "error") {
|
if (conn.status === "error") {
|
||||||
@@ -46,12 +51,6 @@ export const InternalPage: FC<PageProps> = ({ children, api }) => {
|
|||||||
if (snackbarKeyHAConKey.current) {
|
if (snackbarKeyHAConKey.current) {
|
||||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
||||||
}
|
}
|
||||||
snackbarKeyHAConKey.current = snackbar.enqueueSnackbar(
|
|
||||||
`Connecting to websocket...`,
|
|
||||||
{
|
|
||||||
variant: "info",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if (conn.status === "loaded") {
|
} else if (conn.status === "loaded") {
|
||||||
if (snackbarKeyHAConKey.current) {
|
if (snackbarKeyHAConKey.current) {
|
||||||
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
snackbar.closeSnackbar(snackbarKeyHAConKey.current);
|
||||||
@@ -60,15 +59,38 @@ export const InternalPage: FC<PageProps> = ({ children, api }) => {
|
|||||||
}, [conn, snackbar]);
|
}, [conn, snackbar]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={["page", "column", isMobile ? "mobile" : ""].join(" ")}>
|
<ConfirmProvider
|
||||||
<div className="page-contents column">{children}</div>
|
defaultOptions={{
|
||||||
<BottomBar api={api} />
|
cancellationText: lang.get("CLOSE"),
|
||||||
<style>
|
confirmationText: lang.get("CONFIRM"),
|
||||||
{`:root {
|
}}
|
||||||
${convertPaletteToCss(theme.palette)}
|
>
|
||||||
}`}
|
<main className={["page", "column", isMobile ? "mobile" : ""].join(" ")}>
|
||||||
</style>
|
<div className="page-contents column">{children}</div>
|
||||||
</main>
|
<BottomBar api={api} />
|
||||||
|
<style>
|
||||||
|
{`:root {
|
||||||
|
${convertPaletteToCss(theme.palette)}
|
||||||
|
}`}
|
||||||
|
</style>
|
||||||
|
</main>
|
||||||
|
</ConfirmProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const InternalPage: FC<PageProps> = ({ children, api }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { isMobile } = useWindowSize();
|
||||||
|
const lang = useLang();
|
||||||
|
|
||||||
|
if (!lang.ready) {
|
||||||
|
return <Skeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BareInternalPage api={api} isMobile={isMobile} theme={theme} lang={lang}>
|
||||||
|
{children}
|
||||||
|
</BareInternalPage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,24 +107,22 @@ export const Page: FC<PageProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<ConfirmProvider>
|
<SnackbarProvider
|
||||||
<SnackbarProvider
|
anchorOrigin={{
|
||||||
anchorOrigin={{
|
vertical: "bottom",
|
||||||
vertical: "bottom",
|
horizontal: "center",
|
||||||
horizontal: "center",
|
}}
|
||||||
}}
|
ref={notistackRef}
|
||||||
ref={notistackRef}
|
action={(key) => <Button onClick={onClickDismiss(key)}>Dismiss</Button>}
|
||||||
action={(key) => (
|
dense
|
||||||
<Button onClick={onClickDismiss(key)}>Dismiss</Button>
|
preventDuplicate
|
||||||
)}
|
>
|
||||||
dense
|
<ApiStateProvider value={props.api.state}>
|
||||||
preventDuplicate
|
<LangProvider>
|
||||||
>
|
|
||||||
<ApiStateProvider value={props.api.state}>
|
|
||||||
<InternalPage {...props} />
|
<InternalPage {...props} />
|
||||||
</ApiStateProvider>
|
</LangProvider>
|
||||||
</SnackbarProvider>
|
</ApiStateProvider>
|
||||||
</ConfirmProvider>
|
</SnackbarProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
} from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||||
import { SelectorNumber, SelectorText } from "haService/fieldTypes";
|
import { SelectorNumber, SelectorText } from "services/ha/fieldTypes";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "./ServiceEditorTarget.css";
|
import "./ServiceEditorTarget.css";
|
||||||
import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
import { InputDevice } from "components/Inputs/AutoComplete/InputDevice";
|
||||||
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
import { InputEntity } from "components/Inputs/AutoComplete/InputEntities";
|
||||||
import { Targets } from "haService/fieldTypes";
|
import { Targets } from "services/ha/fieldTypes";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { InputArea } from "components/Inputs/AutoComplete/InputArea";
|
import { InputArea } from "components/Inputs/AutoComplete/InputArea";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { ServiceEditor } from ".";
|
import { ServiceEditor } from ".";
|
||||||
import { TypedHassService } from "haService/fieldTypes";
|
import { TypedHassService } from "services/ha/fieldTypes";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
|
|
||||||
import { makeStory } from "devUtils";
|
import { makeStory } from "devUtils";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
import { cleanUpUndefined } from "utils/helpers";
|
import { cleanUpUndefined } from "utils/helpers";
|
||||||
import { TypedHassService } from "haService/fieldTypes";
|
import { TypedHassService } from "services/ha/fieldTypes";
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import {
|
import {
|
||||||
ServiceEditorOption,
|
ServiceEditorOption,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BaseOption } from "components/Inputs/AutoComplete/InputAutoComplete";
|
import { BaseOption } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||||
import { FieldData, TypedHassService } from "haService/fieldTypes";
|
import { FieldData, TypedHassService } from "services/ha/fieldTypes";
|
||||||
import { prettyName } from "utils/formatting";
|
import { prettyName } from "utils/formatting";
|
||||||
|
|
||||||
export type ServiceEditorData = {
|
export type ServiceEditorData = {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import "styles/root.css";
|
|||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
import { Page } from "components/Page";
|
import { Page } from "components/Page";
|
||||||
import { ComponentProps, JSXElementConstructor } from "react";
|
import { ComponentProps, JSXElementConstructor } from "react";
|
||||||
import { ApiService } from "apiService/core";
|
import { ApiService } from "services/api/core";
|
||||||
import { useConnectedApiService, useMockApiService } from "apiService";
|
import { useConnectedApiService, useMockApiService } from "services/api";
|
||||||
|
|
||||||
export type MakeStoryArgs<
|
export type MakeStoryArgs<
|
||||||
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
|
T extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>
|
||||||
@@ -29,10 +29,12 @@ export const makeStory = <
|
|||||||
};
|
};
|
||||||
const Template: ComponentStory<T> = (args) => {
|
const Template: ComponentStory<T> = (args) => {
|
||||||
let api: ApiService;
|
let api: ApiService;
|
||||||
|
const connApi = useConnectedApiService();
|
||||||
|
const mockApi = useMockApiService([]);
|
||||||
if (useLiveApi) {
|
if (useLiveApi) {
|
||||||
api = useConnectedApiService();
|
api = connApi;
|
||||||
} else {
|
} else {
|
||||||
api = useMockApiService([]);
|
api = mockApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useConnectedApiService } from "apiService";
|
import { useConnectedApiService } from "services/api";
|
||||||
import { makeStory } from "devUtils";
|
import { makeStory } from "devUtils";
|
||||||
import { AutomationRoute } from "./automation";
|
import { AutomationRoute } from "./automation";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ApiService } from "apiService/core";
|
import { ApiService } from "services/api/core";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import { AutomationManager } from "components/AutomationManager";
|
import { AutomationManager } from "components/AutomationManager";
|
||||||
|
|
||||||
export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => {
|
export const AutomationRoute: FC<{ api: ApiService }> = ({ api }) => {
|
||||||
|
|||||||
File renamed without changes.
@@ -34,15 +34,9 @@ export const makeRemoteAPI = (baseURL: string): API => ({
|
|||||||
return response;
|
return response;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
let error = String(err);
|
|
||||||
|
|
||||||
if (err instanceof Error) {
|
|
||||||
error += ` ${err.stack}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
error,
|
error: `Server error: ${method} ${path}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,6 @@
|
|||||||
import { useAutoMockAPI } from "./mock";
|
import { useAutoMockAPI } from "./mock";
|
||||||
import { makeAutomationAPI } from "./automations";
|
import { makeAutomationAPI } from "./automations";
|
||||||
import { createMockAuto } from "../utils/mocks";
|
import { createMockAuto } from "utils/mocks";
|
||||||
import { AutomationData } from "types/automations";
|
import { AutomationData } from "types/automations";
|
||||||
|
|
||||||
const fakeUseRef = (a: any) => ({ current: a });
|
const fakeUseRef = (a: any) => ({ current: a });
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -21,10 +21,11 @@ export type APIResponse<D> =
|
|||||||
};
|
};
|
||||||
export type Waitable<D> =
|
export type Waitable<D> =
|
||||||
| { ready: undefined }
|
| { ready: undefined }
|
||||||
| ({ ready: true } & APIResponse<D>)
|
| ({ ready: true } & D)
|
||||||
| {
|
| {
|
||||||
ready: false;
|
ready: false;
|
||||||
};
|
};
|
||||||
|
export type ApiWaitable<D> = Waitable<APIResponse<D>>;
|
||||||
export interface ListData<D> {
|
export interface ListData<D> {
|
||||||
params: ListParams;
|
params: ListParams;
|
||||||
totalItems: number;
|
totalItems: number;
|
||||||
@@ -32,8 +33,8 @@ export interface ListData<D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiState {
|
export interface ApiState {
|
||||||
automations: Waitable<ListData<AutomationData>>;
|
automations: ApiWaitable<ListData<AutomationData>>;
|
||||||
userProfile: Waitable<UserProfile>;
|
userProfile: ApiWaitable<UserProfile>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserProfile = {
|
export type UserProfile = {
|
||||||
@@ -2,7 +2,7 @@ import { useState } from "react";
|
|||||||
import { ApiState } from "./types";
|
import { ApiState } from "./types";
|
||||||
import { AutomationAPI } from "./automations";
|
import { AutomationAPI } from "./automations";
|
||||||
import { UserProfileAPI } from "./profile";
|
import { UserProfileAPI } from "./profile";
|
||||||
import { UserProfile } from "apiService/types";
|
import { UserProfile } from "services/api/types";
|
||||||
|
|
||||||
export const useDefaultApiState = () =>
|
export const useDefaultApiState = () =>
|
||||||
useState<ApiState>({
|
useState<ApiState>({
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-5
@@ -1,7 +1,6 @@
|
|||||||
import React, { FC, useEffect, useState } from "react";
|
import React, { FC, useEffect, useState } from "react";
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
import { makeStory } from "devUtils";
|
||||||
import { Page } from "components/Page";
|
import { useHA } from "services/ha";
|
||||||
import { useHA } from "haService";
|
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { InputList } from "components/Inputs/InputList";
|
import { InputList } from "components/Inputs/InputList";
|
||||||
import { Button } from "components/Inputs/Buttons/Button";
|
import { Button } from "components/Inputs/Buttons/Button";
|
||||||
@@ -78,8 +77,6 @@ const Test: FC = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
import { makeStory } from "devUtils";
|
|
||||||
|
|
||||||
const { make, componentMeta } = makeStory({
|
const { make, componentMeta } = makeStory({
|
||||||
Component: Test,
|
Component: Test,
|
||||||
meta: {
|
meta: {
|
||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
ERR_INVALID_HTTPS_TO_HTTP,
|
ERR_INVALID_HTTPS_TO_HTTP,
|
||||||
createConnection as _createConnection,
|
createConnection as _createConnection,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { wsURL } from "apiService";
|
import { wsURL } from "services/api";
|
||||||
|
|
||||||
export type HAConnection =
|
export type HAConnection =
|
||||||
| {
|
| {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { FC } from "react";
|
import React, { FC } from "react";
|
||||||
import { useHADeviceRegistry } from "haService";
|
import { useHADeviceRegistry } from "services/ha";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { makeStory } from "devUtils";
|
import { makeStory } from "devUtils";
|
||||||
|
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import React, { FC, useState } from "react";
|
import React, { FC, useState } from "react";
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
import { MockPage } from "components/Page";
|
import { MockPage } from "components/Page";
|
||||||
import { useHAEntities } from "haService/HAEntities";
|
import { useHAEntities } from "services/ha/HAEntities";
|
||||||
|
|
||||||
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||||
const [searchTerm, setSearch] = useState("");
|
const [searchTerm, setSearch] = useState("");
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { FC } from "react";
|
import React, { FC } from "react";
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
import { MockPage } from "components/Page";
|
import { MockPage } from "components/Page";
|
||||||
import { useHAEntityRegistry } from "haService";
|
import { useHAEntityRegistry } from "services/ha";
|
||||||
|
|
||||||
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
const Test: FC<{ onRender: () => void }> = ({ onRender }) => {
|
||||||
const conn = useHAEntityRegistry();
|
const conn = useHAEntityRegistry();
|
||||||
File renamed without changes.
File renamed without changes.
@@ -12,7 +12,7 @@ import { TypedHassService } from "./fieldTypes";
|
|||||||
import { Option } from "components/Inputs/AutoComplete/InputAutoComplete";
|
import { Option } from "components/Inputs/AutoComplete/InputAutoComplete";
|
||||||
import { getDeviceExtraWsCalls } from "./extras";
|
import { getDeviceExtraWsCalls } from "./extras";
|
||||||
import { useHAEntities } from "./HAEntities";
|
import { useHAEntities } from "./HAEntities";
|
||||||
import { useLang } from "lang";
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
export type ServiceOption = Option<{
|
export type ServiceOption = Option<{
|
||||||
domain: string;
|
domain: string;
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import React, { FC, useEffect, useState } from "react";
|
import React, { FC, useEffect, useState } from "react";
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
import { MockPage } from "components/Page";
|
import { MockPage } from "components/Page";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "services/ha";
|
||||||
import InputYaml from "components/Inputs/Base/InputYaml";
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
import { InputList } from "components/Inputs/InputList";
|
import { InputList } from "components/Inputs/InputList";
|
||||||
import { Button } from "components/Inputs/Buttons/Button";
|
import { Button } from "components/Inputs/Buttons/Button";
|
||||||
File renamed without changes.
File renamed without changes.
@@ -19,6 +19,7 @@
|
|||||||
"TEMPLATE": "Template",
|
"TEMPLATE": "Template",
|
||||||
"MODE": "Mode",
|
"MODE": "Mode",
|
||||||
"CLOSE": "Close",
|
"CLOSE": "Close",
|
||||||
|
"CONFIRM": "Confirm",
|
||||||
"DESCRIPTION": "Description",
|
"DESCRIPTION": "Description",
|
||||||
"TRIGGER": "Trigger",
|
"TRIGGER": "Trigger",
|
||||||
"CONDITION": "Condition",
|
"CONDITION": "Condition",
|
||||||
@@ -43,6 +44,9 @@
|
|||||||
"YES": "Yes",
|
"YES": "Yes",
|
||||||
"NO": "No",
|
"NO": "No",
|
||||||
|
|
||||||
|
"NEW_VERSION_AVAILABLE": "New Version is Available!",
|
||||||
|
"NEW_VERSION_AVAILABLE_BODY": "Installed version: {{current}}\nLatest version: {{latest}}",
|
||||||
|
|
||||||
"SERVICE": "Service",
|
"SERVICE": "Service",
|
||||||
"REPEAT": "Repeat",
|
"REPEAT": "Repeat",
|
||||||
"WAIT": "Wait",
|
"WAIT": "Wait",
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
"TEMPLATE": "Modèle",
|
"TEMPLATE": "Modèle",
|
||||||
"MODE": "Mode",
|
"MODE": "Mode",
|
||||||
"CLOSE": "Fermer",
|
"CLOSE": "Fermer",
|
||||||
|
"CONFIRM": "Confirmer",
|
||||||
"DESCRIPTION": "Description",
|
"DESCRIPTION": "Description",
|
||||||
"TRIGGER": "Déclencheur",
|
"TRIGGER": "Déclencheur",
|
||||||
"TRIGGERS": "Déclencheurs",
|
"TRIGGERS": "Déclencheurs",
|
||||||
@@ -46,6 +47,9 @@
|
|||||||
"YES": "Oui",
|
"YES": "Oui",
|
||||||
"NO": "Non",
|
"NO": "Non",
|
||||||
|
|
||||||
|
"NEW_VERSION_AVAILABLE": "Une nouvelle version est disponible!",
|
||||||
|
"NEW_VERSION_AVAILABLE_BODY": "Version installée : {{current}}\nDernière version : {{latest}}",
|
||||||
|
|
||||||
"SERVICE": "Service",
|
"SERVICE": "Service",
|
||||||
"REPEAT": "Répéter",
|
"REPEAT": "Répéter",
|
||||||
"WAIT": "Attendre",
|
"WAIT": "Attendre",
|
||||||
@@ -1,11 +1,39 @@
|
|||||||
import { useApiState } from "apiService";
|
import { useApiState } from "services/api";
|
||||||
import { useEffect, useState } from "react";
|
import {
|
||||||
|
FC,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
createContext,
|
||||||
|
PropsWithChildren,
|
||||||
|
useContext,
|
||||||
|
} from "react";
|
||||||
|
import { Waitable } from "../api/types";
|
||||||
|
|
||||||
const MISSING_TEXT = "<<MISSING TEXT -- {{langId}}>>";
|
const MISSING_TEXT = "<<MISSING TEXT -- {{langId}}>>";
|
||||||
const LOADING_TEXT = "...";
|
const LOADING_TEXT = "...";
|
||||||
|
|
||||||
export type LangStore = ReturnType<typeof useLang>;
|
export type LangStore = {
|
||||||
export const useLang = () => {
|
get(langId: string, replacements?: Record<string, string>): string;
|
||||||
|
};
|
||||||
|
const LangContext = createContext<Waitable<LangStore>>({
|
||||||
|
ready: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useLang = (): LangStore & { ready: boolean } => {
|
||||||
|
const langState = useContext(LangContext);
|
||||||
|
|
||||||
|
if (langState.ready) {
|
||||||
|
return langState;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ready: false,
|
||||||
|
get() {
|
||||||
|
return LOADING_TEXT;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LangProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||||
const apiState = useApiState();
|
const apiState = useApiState();
|
||||||
const [langStore, setLangStore] =
|
const [langStore, setLangStore] =
|
||||||
useState<Record<string, string> | null>(null);
|
useState<Record<string, string> | null>(null);
|
||||||
@@ -37,7 +65,7 @@ export const useLang = () => {
|
|||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
const methods = {
|
||||||
get: (langId: string, replacements: Record<string, string> = {}) => {
|
get: (langId: string, replacements: Record<string, string> = {}) => {
|
||||||
let out = LOADING_TEXT;
|
let out = LOADING_TEXT;
|
||||||
if (langStore !== null) {
|
if (langStore !== null) {
|
||||||
@@ -54,4 +82,14 @@ export const useLang = () => {
|
|||||||
return updateParams(out, { ...replacements, langId });
|
return updateParams(out, { ...replacements, langId });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const value: Waitable<LangStore> =
|
||||||
|
langStore === null && langEngStore === null
|
||||||
|
? { ready: false }
|
||||||
|
: {
|
||||||
|
ready: true,
|
||||||
|
...methods,
|
||||||
|
};
|
||||||
|
|
||||||
|
return <LangContext.Provider value={value}>{children}</LangContext.Provider>;
|
||||||
};
|
};
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"TEMPLATE": "Modello",
|
"TEMPLATE": "Modello",
|
||||||
"MODE": "Modalità",
|
"MODE": "Modalità",
|
||||||
"CLOSE": "Chiudi",
|
"CLOSE": "Chiudi",
|
||||||
|
"CONFIRM": "Confermare",
|
||||||
"DESCRIPTION": "Descrizione",
|
"DESCRIPTION": "Descrizione",
|
||||||
"TRIGGER": "Attivazione",
|
"TRIGGER": "Attivazione",
|
||||||
"CONDITION": "Condizione",
|
"CONDITION": "Condizione",
|
||||||
@@ -43,6 +44,9 @@
|
|||||||
"YES": "Sì",
|
"YES": "Sì",
|
||||||
"NO": "No",
|
"NO": "No",
|
||||||
|
|
||||||
|
"NEW_VERSION_AVAILABLE": "È disponibile una nuova versione!",
|
||||||
|
"NEW_VERSION_AVAILABLE_BODY": "Versione installata: {{current}}\nUltima versione: {{latest}}",
|
||||||
|
|
||||||
"SERVICE": "Chiama Servizio",
|
"SERVICE": "Chiama Servizio",
|
||||||
"REPEAT": "Ripeti",
|
"REPEAT": "Ripeti",
|
||||||
"WAIT": "Attesa",
|
"WAIT": "Attesa",
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { parseVersion, Version } from ".";
|
||||||
|
import { VersionComp, compareVersions } from "./index";
|
||||||
|
|
||||||
|
for (const [verStr, expectedVer] of [
|
||||||
|
[
|
||||||
|
"1.2.3",
|
||||||
|
{
|
||||||
|
main: 1,
|
||||||
|
minor: 2,
|
||||||
|
patch: 3,
|
||||||
|
extra: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"20.1.10",
|
||||||
|
{
|
||||||
|
main: 20,
|
||||||
|
minor: 1,
|
||||||
|
patch: 10,
|
||||||
|
extra: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"20.1.10-g1234",
|
||||||
|
{
|
||||||
|
main: 20,
|
||||||
|
minor: 1,
|
||||||
|
patch: 10,
|
||||||
|
extra: "g1234",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
["x.1.10-g1234", null],
|
||||||
|
["2.x1.10-g1234", null],
|
||||||
|
["2.123x.10-g1234", null],
|
||||||
|
["2.123.10g1234", null],
|
||||||
|
] as [string, Version | null][]) {
|
||||||
|
test(`parse version - ${verStr} to be ${JSON.stringify(expectedVer)}`, () => {
|
||||||
|
const version = parseVersion(verStr);
|
||||||
|
expect(version).toEqual(expectedVer);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const [lh, rh, comp] of [
|
||||||
|
[parseVersion("1.1.0"), parseVersion("1.1.0"), null],
|
||||||
|
[null, null, null],
|
||||||
|
[parseVersion("1.1.0"), parseVersion("1.1.0"), null],
|
||||||
|
[parseVersion("1.2.0"), parseVersion("1.1.0"), "left"],
|
||||||
|
[parseVersion("1.2.0"), parseVersion("1.3.0"), "right"],
|
||||||
|
[parseVersion("1.2.0"), parseVersion("2.2.0"), "right"],
|
||||||
|
[parseVersion("1.2.0"), parseVersion("1.2.1"), "right"],
|
||||||
|
[parseVersion("3.2.1"), parseVersion("1.2.1"), "right"],
|
||||||
|
[parseVersion("1.3.1"), parseVersion("1.2.1"), "right"],
|
||||||
|
[parseVersion("1.2.2"), parseVersion("1.2.1"), "right"],
|
||||||
|
] as Array<[Version | null, Version | null, VersionComp]>)
|
||||||
|
test(`compare versions ${lh} ? ${rh} = ${comp}`, () => {
|
||||||
|
expect(compareVersions(lh, rh) === comp);
|
||||||
|
});
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
import * as yaml from "js-yaml";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { ApiWaitable } from "services/api/types";
|
||||||
|
import { useCookies } from "react-cookie";
|
||||||
|
import { useConfirm } from "material-ui-confirm";
|
||||||
|
import { useLang } from "services/lang";
|
||||||
|
|
||||||
|
export const useVersioner = () => {
|
||||||
|
const [
|
||||||
|
cookies,
|
||||||
|
setCookies,
|
||||||
|
// eslint-disable-next-line
|
||||||
|
_,
|
||||||
|
] = useCookies(["versionUpdateNotifier"]);
|
||||||
|
const [latestVersion, setLatestVersion] = useState<
|
||||||
|
ApiWaitable<Version | null>
|
||||||
|
>({
|
||||||
|
ready: false,
|
||||||
|
});
|
||||||
|
const current = parseVersion(
|
||||||
|
process.env.REACT_APP_BUILD_VERSION?.slice(1) ?? "0.0.0"
|
||||||
|
);
|
||||||
|
const confirm = useConfirm();
|
||||||
|
const lang = useLang();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch(
|
||||||
|
"https://raw.githubusercontent.com/asosnovsky/Shortumation/main/config.yaml"
|
||||||
|
)
|
||||||
|
.then(async (resp) => {
|
||||||
|
if (resp.ok) {
|
||||||
|
const dataString = await resp.text();
|
||||||
|
const data = yaml.load(dataString) as any;
|
||||||
|
console.log({ data, dataString });
|
||||||
|
setLatestVersion({
|
||||||
|
ok: true,
|
||||||
|
ready: true,
|
||||||
|
data: parseVersion((data.version ?? "").slice(1)),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setLatestVersion({
|
||||||
|
ready: true,
|
||||||
|
ok: false,
|
||||||
|
error: "failed parsing",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setLatestVersion({
|
||||||
|
ready: true,
|
||||||
|
ok: false,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const currentVersionString = versionToString(current);
|
||||||
|
const latestVersionString =
|
||||||
|
latestVersion.ready && latestVersion.ok
|
||||||
|
? versionToString(latestVersion.data)
|
||||||
|
: "n/a";
|
||||||
|
|
||||||
|
if (current && latestVersion.ready && latestVersion.ok) {
|
||||||
|
if (cookies.versionUpdateNotifier !== latestVersionString) {
|
||||||
|
if (compareVersions(current, latestVersion.data) === "right") {
|
||||||
|
confirm({
|
||||||
|
title: lang.get("NEW_VERSION_AVAILABLE"),
|
||||||
|
cancellationButtonProps: {
|
||||||
|
style: { display: "none" },
|
||||||
|
},
|
||||||
|
content: (
|
||||||
|
<div>
|
||||||
|
<ul>
|
||||||
|
{lang
|
||||||
|
.get("NEW_VERSION_AVAILABLE_BODY", {
|
||||||
|
latest: "v" + latestVersionString,
|
||||||
|
current: "v" + currentVersionString,
|
||||||
|
})
|
||||||
|
.split("\n")
|
||||||
|
.map((p, i) => (
|
||||||
|
<li key={i}>{p}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
}).then(() => setCookies("versionUpdateNotifier", latestVersionString));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
get current() {
|
||||||
|
return currentVersionString;
|
||||||
|
},
|
||||||
|
get latest() {
|
||||||
|
return latestVersionString;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Version = {
|
||||||
|
main: number;
|
||||||
|
minor: number;
|
||||||
|
patch: number;
|
||||||
|
extra: string;
|
||||||
|
};
|
||||||
|
export const parseVersion = (verStr: string): null | Version => {
|
||||||
|
const verArr = verStr.split(".");
|
||||||
|
if (verArr.length !== 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const [mainStr, minorStr, patchAndExtra] = verArr;
|
||||||
|
let extra = "";
|
||||||
|
let patchStr = "";
|
||||||
|
const patchAndExtraArr = patchAndExtra.split("-");
|
||||||
|
if (patchAndExtraArr.length === 2) {
|
||||||
|
[patchStr, extra] = patchAndExtraArr;
|
||||||
|
} else {
|
||||||
|
patchStr = patchAndExtra;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const [main, minor, patch] = [mainStr, minorStr, patchStr].map(Number);
|
||||||
|
if (
|
||||||
|
Number.isInteger(main) &&
|
||||||
|
Number.isInteger(minor) &&
|
||||||
|
Number.isInteger(patch)
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
main,
|
||||||
|
minor,
|
||||||
|
patch,
|
||||||
|
extra,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (_: any) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export type VersionComp = ReturnType<typeof compareVersions>;
|
||||||
|
export const compareVersions = (
|
||||||
|
v1: Version | null,
|
||||||
|
v2: Version | null
|
||||||
|
): "left" | "right" | null => {
|
||||||
|
if (v1 === null && v2 === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (v1 === null) {
|
||||||
|
return "right";
|
||||||
|
}
|
||||||
|
if (v2 === null) {
|
||||||
|
return "left";
|
||||||
|
}
|
||||||
|
for (const key of ["main", "minor", "patch"] as Array<keyof Version>) {
|
||||||
|
if (v1[key] > v2[key]) {
|
||||||
|
return "left";
|
||||||
|
}
|
||||||
|
if (v1[key] < v2[key]) {
|
||||||
|
return "right";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const versionToString = (v: null | Version): string => {
|
||||||
|
if (v) {
|
||||||
|
let out = `${v.main}.${v.minor}.${v.patch}`;
|
||||||
|
if (v.extra) {
|
||||||
|
return out + `-${v.extra}`;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
return "n/a";
|
||||||
|
};
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import { createContext, useContext } from "react"
|
|
||||||
|
|
||||||
export interface TooltipSearchOption {
|
|
||||||
searchObject: string;
|
|
||||||
searchText: string;
|
|
||||||
filterObjects: Record<string, string>;
|
|
||||||
}
|
|
||||||
export interface TooltipState {
|
|
||||||
domrect?: DOMRect;
|
|
||||||
searchOptions?: TooltipSearchOption;
|
|
||||||
onSelected?: (s: string) => void;
|
|
||||||
searchResults: string[];
|
|
||||||
updateState: (s: TooltipState) => void;
|
|
||||||
}
|
|
||||||
export const TooltipContext = createContext<TooltipState>({
|
|
||||||
updateState(s) {},
|
|
||||||
searchResults: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
export const useToolTip = () => {
|
|
||||||
const state = useContext(TooltipContext);
|
|
||||||
|
|
||||||
return {
|
|
||||||
setFocus(
|
|
||||||
domrect: DOMRect,
|
|
||||||
searchOptions: TooltipSearchOption,
|
|
||||||
onSelected: (s: string) => void
|
|
||||||
){
|
|
||||||
state.updateState({
|
|
||||||
...state,
|
|
||||||
domrect, searchOptions, onSelected
|
|
||||||
})
|
|
||||||
},
|
|
||||||
setSearchResults(searchResults: string[]){
|
|
||||||
state.updateState({
|
|
||||||
...state,
|
|
||||||
searchResults
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import { TooltipState } from "./context";
|
|
||||||
|
|
||||||
export default function Tooltip({
|
|
||||||
domrect,
|
|
||||||
searchOptions,
|
|
||||||
searchResults=[],
|
|
||||||
onSelected=()=>{},
|
|
||||||
updateState,
|
|
||||||
}: TooltipState) {
|
|
||||||
|
|
||||||
// state alias
|
|
||||||
const rootClassName = !!domrect && !!searchOptions ? "tooltip show" : "tooltip hide";
|
|
||||||
let tooltipStyle = {};
|
|
||||||
if (domrect) {
|
|
||||||
const {left=0, top=0, height=0, width=0} = domrect;
|
|
||||||
tooltipStyle = {
|
|
||||||
top: `${top + height}px`,
|
|
||||||
left: `${left}px`,
|
|
||||||
width: `${width}px`,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const unFocus = () => updateState({
|
|
||||||
updateState,
|
|
||||||
onSelected,
|
|
||||||
searchResults: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
return <div className={rootClassName}>
|
|
||||||
<div className="tooltip-bg" onClick={() => unFocus()}></div>
|
|
||||||
<ul style={tooltipStyle}>
|
|
||||||
{searchResults.map((r, i) => <li key={i} onClick={() => {
|
|
||||||
onSelected(r);
|
|
||||||
unFocus();
|
|
||||||
}}>
|
|
||||||
{r}
|
|
||||||
</li>)}
|
|
||||||
{searchResults.length === 0 ? <li onClick={() => unFocus()}>No Options...</li> : ""}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user