Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f061894430 | ||
|
|
7769ba00c3 | ||
|
|
18241c2057 | ||
|
|
8b516d958c | ||
|
|
6422b8d974 | ||
|
|
ee77edea78 | ||
|
|
4d667d1432 | ||
|
|
3df79c17d6 | ||
|
|
5b920d366e | ||
|
|
201912f471 | ||
|
|
117595f63f | ||
|
|
a5aec24686 | ||
|
|
8a6415a58b | ||
|
|
d7ca62afa7 | ||
|
|
8fea6f1082 | ||
|
|
51bac6f0e9 | ||
|
|
7020c6aee9 | ||
|
|
41dc77ff4f | ||
|
|
c5cf8edfd6 | ||
|
|
2dca59fa3f | ||
|
|
df95265af0 | ||
|
|
78057939da | ||
|
|
a4a607768a | ||
|
|
a9b2bdb775 | ||
|
|
eee37346ab | ||
|
|
6ee7ce8f70 | ||
|
|
2dfbc31b5d | ||
|
|
ab4997494d | ||
|
|
83b1c85043 |
No files matched your search
@@ -1,5 +1,14 @@
|
|||||||
# Changelog 
|
# Changelog 
|
||||||
|
|
||||||
|
## [0.7.6] Bugfixes
|
||||||
|
|
||||||
|
- Less deadly error for invalid packages with better logs
|
||||||
|
- Update notification
|
||||||
|
|
||||||
|
## [0.7.4] Bugfixes
|
||||||
|
|
||||||
|
- Backend now correctly returns unset alias + description
|
||||||
|
|
||||||
## [0.7.1] Bugfixes + Italian!
|
## [0.7.1] Bugfixes + Italian!
|
||||||
|
|
||||||
- Added support for automations that do not have an `id`
|
- Added support for automations that do not have an `id`
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
:no_entry: [DEPRECATED] Due to lack of time on my part, this project is no longer being worked on. :( :no_entry: [DEPRECATED]
|
||||||
|
|
||||||
|
----
|
||||||
# <img src="logo.png" height="40x"/> Shortumation 
|
# <img src="logo.png" height="40x"/> Shortumation 
|
||||||
|
|
||||||
[](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml)
|
[](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
get_index # unused function (src/api/app.py:41)
|
get_index # unused function (src/api/app.py:41)
|
||||||
list_autos # unused function (src/api/routes/automations.py:14)
|
list_autos # unused function (src/api/routes/automations.py:14)
|
||||||
insert_auto # unused function (src/api/routes/automations.py:30)
|
insert_auto # unused function (src/api/routes/automations.py:30)
|
||||||
update_auto # unused function (src/api/routes/automations.py:35)
|
update_auto # unused function (src/api/routes/automations.py:37)
|
||||||
delete_auto # unused function (src/api/routes/automations.py:45)
|
delete_auto # unused function (src/api/routes/automations.py:49)
|
||||||
read_details # unused function (src/api/routes/details.py:12)
|
read_details # unused function (src/api/routes/details.py:12)
|
||||||
read_profile # unused function (src/api/routes/details.py:24)
|
read_profile # unused function (src/api/routes/details.py:24)
|
||||||
save_profile # unused function (src/api/routes/details.py:28)
|
save_profile # unused function (src/api/routes/details.py:28)
|
||||||
@@ -26,5 +26,6 @@ _.automation_tags # unused property (src/hass_config/loader.py:28)
|
|||||||
json_dumps # unused function (src/json_serializer.py:5)
|
json_dumps # unused function (src/json_serializer.py:5)
|
||||||
theme # unused variable (src/user_profile.py:10)
|
theme # unused variable (src/user_profile.py:10)
|
||||||
lang # unused variable (src/user_profile.py:11)
|
lang # unused variable (src/user_profile.py:11)
|
||||||
SecretValue # unused class (src/yaml_serializer/__init__.py:48)
|
flags # unused variable (src/user_profile.py:12)
|
||||||
EnvVar # unused class (src/yaml_serializer/__init__.py:186)
|
SecretValue # unused class (src/yaml_serializer/__init__.py:55)
|
||||||
|
EnvVar # unused class (src/yaml_serializer/__init__.py:193)
|
||||||
+3
-3
@@ -5,8 +5,8 @@ setuptools.setup(
|
|||||||
python_requires=">=3.10",
|
python_requires=">=3.10",
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"PyYAML==6.0",
|
"PyYAML==6.0",
|
||||||
"fastapi==0.78.0",
|
"fastapi==0.109.1",
|
||||||
"pydantic==1.9.1",
|
"pydantic==1.10.13",
|
||||||
"hypercorn==0.13.2",
|
"hypercorn==0.13.2",
|
||||||
"python-decouple==3.6",
|
"python-decouple==3.6",
|
||||||
"websockets==10.3",
|
"websockets==10.3",
|
||||||
@@ -22,7 +22,7 @@ setuptools.setup(
|
|||||||
"pre-commit==2.20.0",
|
"pre-commit==2.20.0",
|
||||||
"vulture==2.5",
|
"vulture==2.5",
|
||||||
"types-requests==2.28.4",
|
"types-requests==2.28.4",
|
||||||
"types-PyYAML==6.0.11",
|
"types-PyYAML==6.0.12.20240311",
|
||||||
"requests==2.28.1",
|
"requests==2.28.1",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ class FailedDeletion(AutomationLoaderException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidPackage(AutomationLoaderException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DBError(Exception):
|
class DBError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
from itertools import chain
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Iterator, Tuple, Union
|
from typing import Any, Iterator, Tuple, Union
|
||||||
|
|
||||||
@@ -16,7 +15,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 +45,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 +57,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 +86,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 +99,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 +115,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 +130,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 +140,48 @@ 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):
|
logger.info(f"Loading package={package_name}:{type(package_data)} from {package_data}")
|
||||||
package_mapping = package_data.to_normalized_json()
|
try:
|
||||||
yield from extract_automation_from_package(
|
if isinstance(package_data, IncludedYaml):
|
||||||
package_data=package_mapping,
|
package_mapping = package_data.to_normalized_json()
|
||||||
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,
|
||||||
|
)
|
||||||
|
elif package_data is not None:
|
||||||
|
raise InvalidPackage(
|
||||||
|
f"configurations.homeassistant.packages.{package_name} must be a dictionary but got {type(package_data)}!"
|
||||||
|
)
|
||||||
|
except InvalidPackage 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,47 +33,35 @@ 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] = []
|
||||||
condition: list[dict] = []
|
condition: list[dict] = []
|
||||||
action: list[dict] = []
|
action: list[dict] = []
|
||||||
|
|
||||||
def to_primitive(self, exclude_unset=True, exclude_none=True, **kwrgs):
|
def to_primitive(self):
|
||||||
return BaseModel.dict(self, exclude_unset=exclude_unset, exclude_none=exclude_none, **kwrgs)
|
return self.dict(exclude_unset=True, exclude_none=True)
|
||||||
|
|
||||||
def dict(self, **kwrgs):
|
|
||||||
kwrgs["exclude_unset"] = True
|
|
||||||
kwrgs["exclude_none"] = True
|
|
||||||
return self.to_primitive(
|
|
||||||
**kwrgs,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Automation(BaseAutomation):
|
class Automation(BaseAutomation):
|
||||||
tags: dict[str, str] = Field(default_factory=dict)
|
tags: dict[str, str] = Field(default_factory=dict)
|
||||||
|
|
||||||
def to_primitive(self, include_tags: bool = False, **kwrgs):
|
def to_primitive(self, include_tags: bool = False):
|
||||||
out = super().to_primitive(**kwrgs)
|
out = super().to_primitive()
|
||||||
if not include_tags and out.get("tags", None) is not None:
|
if not include_tags and out.get("tags", None) is not None:
|
||||||
del out["tags"]
|
del out["tags"]
|
||||||
if include_tags and out.get("tags", None) is None:
|
|
||||||
out["tags"] = {}
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def dict(self, **kwrgs):
|
|
||||||
return BaseAutomation.dict(self, **kwrgs, include_tags=True)
|
|
||||||
|
|
||||||
|
|
||||||
class ExtenededAutomation(Automation):
|
class ExtenededAutomation(Automation):
|
||||||
source_file: str
|
source_file: str
|
||||||
source_file_type: Literal["list", "obj", "inline"]
|
source_file_type: Literal["list", "obj", "inline"]
|
||||||
configuration_key: ConfigurationKey
|
configuration_key: ConfigurationKey
|
||||||
|
|
||||||
def to_primitive(self, include_tags: bool = False, **kwrgs):
|
def to_primitive(self, include_tags: bool = False):
|
||||||
out = super().to_primitive(include_tags=include_tags, **kwrgs)
|
out = super().to_primitive(include_tags=include_tags)
|
||||||
del out["source_file"]
|
del out["source_file"]
|
||||||
del out["source_file_type"]
|
del out["source_file_type"]
|
||||||
del out["configuration_key"]
|
del out["configuration_key"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import Literal
|
from typing import Dict, Literal
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from src.hass_config import HassConfig
|
from src.hass_config import HassConfig
|
||||||
from src.yaml_serializer import dump_yaml, load_yaml
|
from src.yaml_serializer import dump_yaml, load_yaml
|
||||||
@@ -9,6 +9,7 @@ from src.yaml_serializer import dump_yaml, load_yaml
|
|||||||
class UserProfile(BaseModel):
|
class UserProfile(BaseModel):
|
||||||
theme: Literal["dark", "light"] = "dark"
|
theme: Literal["dark", "light"] = "dark"
|
||||||
lang: str = "eng"
|
lang: str = "eng"
|
||||||
|
flags: Dict[str, bool] = Field(default_factory=dict)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_hass_config(cls, hass_config: HassConfig):
|
def from_hass_config(cls, hass_config: HassConfig):
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
automation: !include ../automations.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
# media_player: !include_dir_list ../entities/media_players
|
||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
automation: !include ../automations.yaml
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
media_player:
|
||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
- platform: media
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
automation: !include ../automations.yaml
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
- platform: ping
|
||||||
|
host: 192.168.0.119
|
||||||
|
name: "Ping Pc Tv"
|
||||||
|
scan_interval: 10
|
||||||
|
- platform: ping
|
||||||
|
host: 192.168.0.181
|
||||||
|
name: "Ping Living Room Tv"
|
||||||
|
scan_interval: 10
|
||||||
|
- platform: ping
|
||||||
|
host: 192.168.0.100
|
||||||
|
name: "Ping Printer"
|
||||||
|
scan_interval: 15
|
||||||
|
- platform: ping
|
||||||
|
host: 192.168.0.177
|
||||||
|
name: "Ping Broadlink"
|
||||||
|
scan_interval: 15
|
||||||
@@ -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(
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ from tests.utils import (
|
|||||||
HA_CONFIG11_EXAMPLE,
|
HA_CONFIG11_EXAMPLE,
|
||||||
HA_CONFIG12_EXAMPLE,
|
HA_CONFIG12_EXAMPLE,
|
||||||
HA_CONFIG13_EXAMPLE,
|
HA_CONFIG13_EXAMPLE,
|
||||||
|
HA_CONFIG14_EXAMPLE,
|
||||||
|
HA_CONFIG15_EXAMPLE,
|
||||||
|
HA_CONFIG16_EXAMPLE,
|
||||||
|
HA_CONFIG17_EXAMPLE,
|
||||||
HA_CONFIG_EXAMPLE,
|
HA_CONFIG_EXAMPLE,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -162,6 +166,10 @@ 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),
|
||||||
|
(HA_CONFIG15_EXAMPLE, 1),
|
||||||
|
(HA_CONFIG16_EXAMPLE, 1),
|
||||||
|
(HA_CONFIG17_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,10 @@ 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"
|
||||||
|
HA_CONFIG15_EXAMPLE = SAMPLES_FOLDER / "config-15"
|
||||||
|
HA_CONFIG16_EXAMPLE = SAMPLES_FOLDER / "config-16"
|
||||||
|
HA_CONFIG17_EXAMPLE = SAMPLES_FOLDER / "config-17"
|
||||||
|
|
||||||
|
|
||||||
def get_example_automation_loader(
|
def get_example_automation_loader(
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: Shortumation
|
name: Shortumation
|
||||||
version: v0.7.1
|
version: v0.7.6
|
||||||
slug: shortumation
|
slug: shortumation
|
||||||
image: "asosnovsky/shortumation-{arch}"
|
image: "asosnovsky/shortumation-{arch}"
|
||||||
url: "https://github.com/asosnovsky/Shortumation"
|
url: "https://github.com/asosnovsky/Shortumation"
|
||||||
|
|||||||
+5
-5
@@ -6,19 +6,19 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "11.9.3",
|
"@emotion/react": "11.9.3",
|
||||||
"@emotion/styled": "11.9.3",
|
"@emotion/styled": "11.9.3",
|
||||||
"@mui/icons-material": "5.8.4",
|
"@mui/icons-material": "5.10.6",
|
||||||
"@mui/material": "5.8.6",
|
"@mui/material": "5.10.6",
|
||||||
"@mui/styles": "5.8.6",
|
"@mui/styles": "5.8.6",
|
||||||
"@types/jest": "28.1.8",
|
"@types/jest": "28.1.8",
|
||||||
"@types/node": "17.0.36",
|
"@types/node": "17.0.36",
|
||||||
"@types/react": "18.0.18",
|
"@types/react": "18.0.25",
|
||||||
"@types/react-dom": "18.0.6",
|
"@types/react-dom": "18.0.8",
|
||||||
"@types/ws": "8.5.3",
|
"@types/ws": "8.5.3",
|
||||||
"@uiw/react-codemirror": "4.10.4",
|
"@uiw/react-codemirror": "4.10.4",
|
||||||
"autosuggest-highlight": "3.3.4",
|
"autosuggest-highlight": "3.3.4",
|
||||||
"home-assistant-js-websocket": "7.1.0",
|
"home-assistant-js-websocket": "7.1.0",
|
||||||
"jss": "10.9.2",
|
"jss": "10.9.2",
|
||||||
"material-ui-confirm": "3.0.4",
|
"material-ui-confirm": "3.0.6",
|
||||||
"notistack": "2.0.5",
|
"notistack": "2.0.5",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-cookie": "4.1.1",
|
"react-cookie": "4.1.1",
|
||||||
|
|||||||
+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,9 +0,0 @@
|
|||||||
.automation-editor--nodes-row .collection-nodes--wrap {
|
|
||||||
--node-height: 12em !important;
|
|
||||||
--node-width: 100% !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-editor--nodes-row .collection-nodes--wrap .collection-nodes {
|
|
||||||
min-width: 90%;
|
|
||||||
min-height: 10em;
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
|
||||||
import { makeStory } from "devUtils";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { NodesRow } from ".";
|
|
||||||
|
|
||||||
const { make, componentMeta } = makeStory({
|
|
||||||
Component: NodesRow,
|
|
||||||
BaseTemplate: (props) => {
|
|
||||||
const [data, setData] = useState(props.data);
|
|
||||||
return (
|
|
||||||
<NodesRow
|
|
||||||
{...props}
|
|
||||||
data={data}
|
|
||||||
onUpdate={(up) => {
|
|
||||||
setData(up);
|
|
||||||
props.onUpdate(up);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
meta: {
|
|
||||||
title: "App/AutomationEditor/NodesRow",
|
|
||||||
args: {
|
|
||||||
data: [],
|
|
||||||
sequenceNodeDims: DEFAULT_DIMS.node,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default componentMeta;
|
|
||||||
export const Empty = make({});
|
|
||||||
export const One = make({
|
|
||||||
type: "trigger",
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
platform: "calendar",
|
|
||||||
event: "test",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import "./index.css";
|
|
||||||
|
|
||||||
import { AutomationNode, AutomationNodeMapping } from "types/automations";
|
|
||||||
import { useHA } from "haService";
|
|
||||||
import { CollectionNodeElement } from "components/DAGGraph/nodes/CollectionNode/CollectionNodeElement";
|
|
||||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
|
||||||
import { Size } from "components/DAGGraph/elements/types";
|
|
||||||
|
|
||||||
export type NodesRowProps<
|
|
||||||
K extends keyof AutomationNodeMapping,
|
|
||||||
T extends AutomationNode<K>
|
|
||||||
> = {
|
|
||||||
type: K;
|
|
||||||
data: T[];
|
|
||||||
onUpdate: (d: T[]) => void;
|
|
||||||
sequenceNodeDims: Size;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function NodesRow<
|
|
||||||
K extends keyof AutomationNodeMapping,
|
|
||||||
T extends AutomationNode<K>
|
|
||||||
>({ type: collectionType, data, sequenceNodeDims }: NodesRowProps<K, T>) {
|
|
||||||
const { namer } = useHA();
|
|
||||||
return (
|
|
||||||
<div className="automation-editor--nodes-row">
|
|
||||||
<CollectionNodeElement
|
|
||||||
width={0}
|
|
||||||
height={0}
|
|
||||||
nodes={data.map((node) => ({
|
|
||||||
enabled: node.enabled ?? true,
|
|
||||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
|
||||||
onXClick: () => {},
|
|
||||||
}))}
|
|
||||||
onAddNode={() => {}}
|
|
||||||
collectionType={collectionType}
|
|
||||||
title="if"
|
|
||||||
sequenceNode={sequenceNodeDims}
|
|
||||||
flipped
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -128,3 +128,12 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 1em;
|
gap: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.automation-editor.fullscreen .automation-editor--flow-wrapper--toolbar--title {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor.fullscreen .automation-editor--flow-wrapper--toolbar {
|
||||||
|
justify-content: flex-end;
|
||||||
|
margin-top: 0.5em;
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ import "./index.css";
|
|||||||
import "./index.mobile.css";
|
import "./index.mobile.css";
|
||||||
|
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
|
|
||||||
import Skeleton from "@mui/material/Skeleton";
|
import Skeleton from "@mui/material/Skeleton";
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
@@ -11,7 +10,6 @@ import SpeedDialAction from "@mui/material/SpeedDialAction";
|
|||||||
|
|
||||||
import SpeedDialIcon from "@mui/icons-material/SettingsRounded";
|
import SpeedDialIcon from "@mui/icons-material/SettingsRounded";
|
||||||
import UndoIcon from "@mui/icons-material/UndoSharp";
|
import UndoIcon from "@mui/icons-material/UndoSharp";
|
||||||
import Icon from "@mui/material/Icon";
|
|
||||||
import EditIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
|
import EditIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
|
||||||
import DeleteIcon from "@mui/icons-material/DeleteForever";
|
import DeleteIcon from "@mui/icons-material/DeleteForever";
|
||||||
import { CheckMarkIcon } from "components/Icons";
|
import { CheckMarkIcon } from "components/Icons";
|
||||||
@@ -31,10 +29,19 @@ 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";
|
||||||
|
import { useUserProfile } from "services/api";
|
||||||
|
import {
|
||||||
|
ControlButton,
|
||||||
|
ReactFlowProvider,
|
||||||
|
useReactFlow,
|
||||||
|
} from "react-flow-renderer";
|
||||||
|
import FitInIcon from "@mui/icons-material/FitScreenRounded";
|
||||||
|
import FullscreenIcon from "@mui/icons-material/FullscreenRounded";
|
||||||
|
import FullscreenExitIcon from "@mui/icons-material/FullscreenExitRounded";
|
||||||
|
import { useEffect } from "react";
|
||||||
interface Props {
|
interface Props {
|
||||||
automation?: AutomationData | BareAutomationData;
|
automation?: AutomationData | BareAutomationData;
|
||||||
dims: DAGDims;
|
dims: DAGDims;
|
||||||
@@ -46,7 +53,14 @@ interface Props {
|
|||||||
readonly: boolean;
|
readonly: boolean;
|
||||||
issue?: string;
|
issue?: string;
|
||||||
}
|
}
|
||||||
export const AutomationEditor: FC<Props> = ({
|
export const AutomationEditor: FC<Props> = (props) => {
|
||||||
|
return (
|
||||||
|
<ReactFlowProvider>
|
||||||
|
<AutomationEditorInner {...props} />
|
||||||
|
</ReactFlowProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const AutomationEditorInner: FC<Props> = ({
|
||||||
dims,
|
dims,
|
||||||
automation: propsAutos,
|
automation: propsAutos,
|
||||||
onUpdate: propsOnUpdate,
|
onUpdate: propsOnUpdate,
|
||||||
@@ -57,6 +71,8 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
issue,
|
issue,
|
||||||
}) => {
|
}) => {
|
||||||
// state
|
// state
|
||||||
|
const reactFlow = useReactFlow();
|
||||||
|
const userProfile = useUserProfile();
|
||||||
const langStore = useLang();
|
const langStore = useLang();
|
||||||
const snackbr = useSnackbar();
|
const snackbr = useSnackbar();
|
||||||
const {
|
const {
|
||||||
@@ -79,15 +95,18 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const [infoBoxOpen, setInfoBox] = useState(false);
|
const [infoBoxOpen, setInfoBox] = useState(false);
|
||||||
const [
|
const [fullScreenMode, setFullScreenMode] = useState(false);
|
||||||
{ ckFlipped },
|
|
||||||
setCookies,
|
|
||||||
// eslint-disable-next-line
|
|
||||||
_,
|
|
||||||
] = useCookies(["ckFlipped"]);
|
|
||||||
// alias
|
// alias
|
||||||
const flipped = dims.flipped ? true : ckFlipped === "1";
|
const flipped = userProfile.flags.flipped ?? !dims.flipped;
|
||||||
const setFlipped = (v: boolean) => setCookies("ckFlipped", v ? "1" : "0");
|
const useNodesRow = userProfile.flags.useNodesRow !== false;
|
||||||
|
// effect
|
||||||
|
useEffect(() => {
|
||||||
|
if (reactFlow) {
|
||||||
|
setTimeout(() => {
|
||||||
|
reactFlow.fitView();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}, [flipped, fullScreenMode, reactFlow]);
|
||||||
// render
|
// render
|
||||||
if (state.status === "loading") {
|
if (state.status === "loading") {
|
||||||
return (
|
return (
|
||||||
@@ -114,6 +133,7 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
"automation-editor",
|
"automation-editor",
|
||||||
state.status,
|
state.status,
|
||||||
readonly ? "readonly" : "",
|
readonly ? "readonly" : "",
|
||||||
|
fullScreenMode ? "fullscreen" : "",
|
||||||
].join(" ")}
|
].join(" ")}
|
||||||
>
|
>
|
||||||
{state.status === "saving" && (
|
{state.status === "saving" && (
|
||||||
@@ -220,15 +240,6 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{!dims.flipped && (
|
|
||||||
<Button
|
|
||||||
className={"automation-editor--flow-wrapper--toolbar--flip-btn"}
|
|
||||||
onClick={() => setFlipped(!flipped)}
|
|
||||||
>
|
|
||||||
<Icon>{flipped ? "flip_to_front" : "flip_to_back"}</Icon>
|
|
||||||
{langStore.get("FLIPP")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{state.status === "changed" && (
|
{state.status === "changed" && (
|
||||||
<Button onClick={undo}>
|
<Button onClick={undo}>
|
||||||
<UndoIcon />
|
<UndoIcon />
|
||||||
@@ -255,6 +266,17 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
onTriggerUpdate={updateTrigger}
|
onTriggerUpdate={updateTrigger}
|
||||||
onConditionUpdate={updateCondition}
|
onConditionUpdate={updateCondition}
|
||||||
isFlipped={flipped}
|
isFlipped={flipped}
|
||||||
|
useNodesRow={useNodesRow}
|
||||||
|
additionalControls={
|
||||||
|
<>
|
||||||
|
<ControlButton onClick={() => setFullScreenMode(!fullScreenMode)}>
|
||||||
|
{fullScreenMode ? <FullscreenExitIcon /> : <FullscreenIcon />}
|
||||||
|
</ControlButton>
|
||||||
|
<ControlButton onClick={() => reactFlow.fitView()}>
|
||||||
|
<FitInIcon />
|
||||||
|
</ControlButton>
|
||||||
|
</>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<SpeedDial
|
<SpeedDial
|
||||||
ariaLabel="options label"
|
ariaLabel="options label"
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -6,6 +6,11 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
min-width: calc(min(max(25vw, 35em), 50vw));
|
min-width: calc(min(max(25vw, 35em), 50vw));
|
||||||
|
transition: min-width ease-in-out 500ms,
|
||||||
|
min-height ease-in-out 500ms,
|
||||||
|
height ease-in-out 500ms,
|
||||||
|
width ease-in-out 500ms,
|
||||||
|
opacity ease-in-out 500ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
.automation-manager--sidebar-box--nav {
|
.automation-manager--sidebar-box--nav {
|
||||||
@@ -35,10 +40,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.automation-manager--sidebar.hidden {
|
.automation-manager--sidebar.hidden {
|
||||||
width: 2.5em;
|
width: 3em;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.automation-manager--sidebar.hidden .add-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--nav,
|
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--nav,
|
||||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--list,
|
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--list,
|
||||||
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--bottom-buttons .add-btn {
|
.automation-manager--sidebar.hidden .automation-manager--sidebar-box--bottom-buttons .add-btn {
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|||||||
@@ -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,11 +1,12 @@
|
|||||||
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";
|
||||||
|
import InputBoolean from "components/Inputs/Base/InputBoolean";
|
||||||
|
|
||||||
export type UserProfileProps = {
|
export type UserProfileProps = {
|
||||||
api: ApiService;
|
api: ApiService;
|
||||||
@@ -43,6 +44,26 @@ export const UserProfileEditor: FC<UserProfileProps> = ({ api }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const updateFlag =
|
||||||
|
<K extends keyof UserProfile["flags"], D extends UserProfile["flags"][K]>(
|
||||||
|
key: K
|
||||||
|
) =>
|
||||||
|
(data: D) => {
|
||||||
|
if (profile.ready) {
|
||||||
|
setIsSaving(true);
|
||||||
|
api
|
||||||
|
.setProfile({
|
||||||
|
...profile.data,
|
||||||
|
flags: {
|
||||||
|
...profile.data.flags,
|
||||||
|
[key]: data,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
setIsSaving(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div className="user-profile">
|
<div className="user-profile">
|
||||||
<InputList
|
<InputList
|
||||||
@@ -57,6 +78,16 @@ export const UserProfileEditor: FC<UserProfileProps> = ({ api }) => {
|
|||||||
current={profile.data.lang}
|
current={profile.data.lang}
|
||||||
onChange={update("lang")}
|
onChange={update("lang")}
|
||||||
/>
|
/>
|
||||||
|
<InputBoolean
|
||||||
|
label={lang.get("FLIPP_GRAPH")}
|
||||||
|
value={profile.data.flags.flipped ?? false}
|
||||||
|
onChange={updateFlag("flipped")}
|
||||||
|
/>
|
||||||
|
<InputBoolean
|
||||||
|
label={lang.get("NODES_ROW")}
|
||||||
|
value={profile.data.flags.useNodesRow ?? true}
|
||||||
|
onChange={updateFlag("useNodesRow")}
|
||||||
|
/>
|
||||||
{saving && <LinearProgress />}
|
{saving && <LinearProgress />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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<{
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||||
|
import { makeStory } from "devUtils";
|
||||||
|
import { NodesRow } from ".";
|
||||||
|
import { createUpdater } from "../updater/index";
|
||||||
|
|
||||||
|
const { make, componentMeta } = makeStory({
|
||||||
|
Component: NodesRow,
|
||||||
|
BaseTemplate: (props) => {
|
||||||
|
const updater = createUpdater({
|
||||||
|
openModal: () => {},
|
||||||
|
action: {
|
||||||
|
data: [],
|
||||||
|
onUpdate: () => {},
|
||||||
|
},
|
||||||
|
condition: {
|
||||||
|
data: [],
|
||||||
|
onUpdate: () => {},
|
||||||
|
},
|
||||||
|
trigger: {
|
||||||
|
data: [],
|
||||||
|
onUpdate: () => {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return <NodesRow {...props} stateUpdater={updater} />;
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
title: "DAGGraph/NodesRow/Single",
|
||||||
|
args: {
|
||||||
|
type: "trigger",
|
||||||
|
data: [],
|
||||||
|
sequenceNodeDims: DEFAULT_DIMS.node,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default componentMeta;
|
||||||
|
export const Empty = make({});
|
||||||
|
export const One = make({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
platform: "calendar",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
export const Many = make({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
platform: "calendar",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
].map((n, id) => ({
|
||||||
|
...n,
|
||||||
|
id: `Trigger ${id}`,
|
||||||
|
})),
|
||||||
|
});
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||||
|
import { makeStory } from "devUtils";
|
||||||
|
import { createUpdater } from "../updater";
|
||||||
|
import { TriggerConditionNodeRow } from ".";
|
||||||
|
|
||||||
|
const { make, componentMeta } = makeStory({
|
||||||
|
Component: TriggerConditionNodeRow,
|
||||||
|
BaseTemplate: (props) => {
|
||||||
|
const updater = createUpdater({
|
||||||
|
openModal: () => {},
|
||||||
|
action: {
|
||||||
|
data: [],
|
||||||
|
onUpdate: () => {},
|
||||||
|
},
|
||||||
|
condition: {
|
||||||
|
data: [],
|
||||||
|
onUpdate: () => {},
|
||||||
|
},
|
||||||
|
trigger: {
|
||||||
|
data: [],
|
||||||
|
onUpdate: () => {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return <TriggerConditionNodeRow {...props} stateUpdater={updater} />;
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
title: "DAGGraph/NodesRow/TriggerAndConditions",
|
||||||
|
args: {
|
||||||
|
condition: [],
|
||||||
|
trigger: [],
|
||||||
|
sequenceNodeDims: DEFAULT_DIMS.node,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default componentMeta;
|
||||||
|
export const Empty = make({});
|
||||||
|
export const One = make({
|
||||||
|
trigger: [
|
||||||
|
{
|
||||||
|
platform: "calendar",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
condition: "and",
|
||||||
|
conditions: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
export const Many = make({
|
||||||
|
trigger: [
|
||||||
|
{
|
||||||
|
platform: "calendar",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "homeassistant",
|
||||||
|
event: "start",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/* .nodes-row--outer {
|
||||||
|
--nodes-row-height: 10em;
|
||||||
|
min-width: 100%;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
|
||||||
|
min-height: var(--nodes-row-height);
|
||||||
|
height: var(--nodes-row-height);
|
||||||
|
max-height: var(--nodes-row-height);
|
||||||
|
|
||||||
|
overflow: auto;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.nodes-row--inner {
|
||||||
|
max-width: calc(100% - 4em);
|
||||||
|
width: calc(100% - 4em);
|
||||||
|
min-height: calc(var(--nodes-row-height) - 2em);
|
||||||
|
max-height: calc(var(--nodes-row-height) - 2em);
|
||||||
|
gap: 2em;
|
||||||
|
|
||||||
|
|
||||||
|
padding-left: 1em;
|
||||||
|
padding-right: 1em;
|
||||||
|
|
||||||
|
border-style: solid;
|
||||||
|
border-top-width: 0.125em;
|
||||||
|
border-left-width: 1px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-radius: 10px;
|
||||||
|
|
||||||
|
border-bottom-color: var(--mui-grey-500);
|
||||||
|
border-left-color: var(--mui-grey-700);
|
||||||
|
border-right-color: var(--mui-grey-700);
|
||||||
|
border-top-color: var(--sequence-node-color);
|
||||||
|
|
||||||
|
overflow: auto;
|
||||||
|
} */
|
||||||
|
|
||||||
|
.nodes-row--inner.collection-nodes--wrap {
|
||||||
|
--node-height: none !important;
|
||||||
|
--node-width: 100% !important;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 95%;
|
||||||
|
max-width: 95%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.nodes-row--inner.collection-nodes--wrap .collection-nodes {
|
||||||
|
min-width: 90%;
|
||||||
|
min-height: 8em;
|
||||||
|
max-height: 8em;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.trigger-condition-nodes-row {
|
||||||
|
gap: 0.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.fullscreen .trigger-condition-nodes-row .nodes-row--inner {
|
||||||
|
opacity: 0;
|
||||||
|
height: 0;
|
||||||
|
z-index: -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nodes-row--inner.collection-nodes--wrap .collection-nodes .collection-nodes--inner {
|
||||||
|
min-width: inherit;
|
||||||
|
width: inherit;
|
||||||
|
max-width: inherit;
|
||||||
|
|
||||||
|
padding-bottom: 0 !important;
|
||||||
|
padding-left: 0 !important;
|
||||||
|
min-height: 5em;
|
||||||
|
max-height: 7em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile .trigger-condition-nodes-row {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.mobile .nodes-row.collection-nodes--wrap .collection-nodes {
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import "./index.css";
|
||||||
|
|
||||||
|
import { AutomationNode, AutomationNodeMapping } from "types/automations";
|
||||||
|
import { useHA } from "services/ha";
|
||||||
|
import { CollectionNodeElement } from "components/DAGGraph/nodes/CollectionNode/CollectionNodeElement";
|
||||||
|
import { Size } from "components/DAGGraph/elements/types";
|
||||||
|
import { DAGGraphUpdater } from "components/DAGGraph/updater";
|
||||||
|
import { makeCollectionNodeMakerChildProps } from "components/DAGGraph/elements/helpers";
|
||||||
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
|
import { AutomationTrigger } from "types/automations/triggers";
|
||||||
|
import { FC } from "react";
|
||||||
|
|
||||||
|
export type NodesRowProps<
|
||||||
|
K extends keyof AutomationNodeMapping,
|
||||||
|
T extends AutomationNode<K>
|
||||||
|
> = {
|
||||||
|
type: K;
|
||||||
|
data: T[];
|
||||||
|
stateUpdater: DAGGraphUpdater;
|
||||||
|
sequenceNodeDims: Size;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function NodesRow<
|
||||||
|
K extends keyof AutomationNodeMapping,
|
||||||
|
T extends AutomationNode<K>
|
||||||
|
>({
|
||||||
|
type: collectionType,
|
||||||
|
data,
|
||||||
|
sequenceNodeDims,
|
||||||
|
stateUpdater,
|
||||||
|
}: NodesRowProps<K, T>) {
|
||||||
|
const { namer } = useHA();
|
||||||
|
return (
|
||||||
|
<div className="nodes-row--outer center row">
|
||||||
|
<CollectionNodeElement
|
||||||
|
className="nodes-row--inner"
|
||||||
|
width={0}
|
||||||
|
height={0}
|
||||||
|
nodes={data.map((node, i) =>
|
||||||
|
makeCollectionNodeMakerChildProps(
|
||||||
|
collectionType,
|
||||||
|
node,
|
||||||
|
i,
|
||||||
|
stateUpdater,
|
||||||
|
namer
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
onAddNode={() => stateUpdater.basic[collectionType].addNode(null)}
|
||||||
|
collectionType={collectionType}
|
||||||
|
sequenceNode={sequenceNodeDims}
|
||||||
|
flipped
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TriggerConditionNodeRowProps = {
|
||||||
|
condition: AutomationCondition[];
|
||||||
|
trigger: AutomationTrigger[];
|
||||||
|
stateUpdater: DAGGraphUpdater;
|
||||||
|
sequenceNodeDims: Size;
|
||||||
|
};
|
||||||
|
export const TriggerConditionNodeRow: FC<TriggerConditionNodeRowProps> = ({
|
||||||
|
condition,
|
||||||
|
trigger,
|
||||||
|
stateUpdater,
|
||||||
|
sequenceNodeDims,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div className={["trigger-condition-nodes-row column"].join(" ")}>
|
||||||
|
<NodesRow
|
||||||
|
data={trigger}
|
||||||
|
type="trigger"
|
||||||
|
stateUpdater={stateUpdater}
|
||||||
|
sequenceNodeDims={sequenceNodeDims}
|
||||||
|
/>
|
||||||
|
<NodesRow
|
||||||
|
data={condition}
|
||||||
|
type="condition"
|
||||||
|
stateUpdater={stateUpdater}
|
||||||
|
sequenceNodeDims={sequenceNodeDims}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -11,7 +11,6 @@ const { make, componentMeta } = makeStory({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default componentMeta;
|
export default componentMeta;
|
||||||
export const Example = make({});
|
|
||||||
|
|
||||||
export const Loading = make({
|
export const Loading = make({
|
||||||
state: {
|
state: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import "./index.css";
|
|||||||
|
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import ReactFlow, { Controls, ReactFlowProvider } from "react-flow-renderer";
|
import ReactFlow, { Controls } from "react-flow-renderer";
|
||||||
|
|
||||||
import { NodeEditor } from "components/NodeEditor";
|
import { NodeEditor } from "components/NodeEditor";
|
||||||
import { Modal } from "components/Modal";
|
import { Modal } from "components/Modal";
|
||||||
@@ -10,15 +10,7 @@ import { Modal } from "components/Modal";
|
|||||||
import { nodeTypes } from "../nodes";
|
import { nodeTypes } from "../nodes";
|
||||||
import { DAGGraphBoardProps } from "./types";
|
import { DAGGraphBoardProps } from "./types";
|
||||||
|
|
||||||
export const DAGGraphBoard: FC<DAGGraphBoardProps> = (props) => {
|
export const DAGGraphBoard: FC<DAGGraphBoardProps> = ({
|
||||||
return (
|
|
||||||
<ReactFlowProvider>
|
|
||||||
<DAGGraphBoardInner {...props} />
|
|
||||||
</ReactFlowProvider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
|
||||||
modalState,
|
modalState,
|
||||||
state,
|
state,
|
||||||
closeModal,
|
closeModal,
|
||||||
@@ -37,6 +29,12 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
|||||||
return <div className="dag-graphboard errored">{state.data.error}</div>;
|
return <div className="dag-graphboard errored">{state.data.error}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// if (state.ready) {
|
||||||
|
// reactFlow.fitView();
|
||||||
|
// }
|
||||||
|
// }, [state.ready, reactFlow]);
|
||||||
|
|
||||||
// modal
|
// modal
|
||||||
let modalBody = <></>;
|
let modalBody = <></>;
|
||||||
if (modalState) {
|
if (modalState) {
|
||||||
@@ -70,7 +68,7 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
|||||||
nodesDraggable={false}
|
nodesDraggable={false}
|
||||||
{...elements}
|
{...elements}
|
||||||
>
|
>
|
||||||
<Controls showInteractive={false} showFitView>
|
<Controls showInteractive={false} showFitView={false}>
|
||||||
{additionalControls}
|
{additionalControls}
|
||||||
</Controls>
|
</Controls>
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { XYPosition } from "react-flow-renderer";
|
|||||||
|
|
||||||
import AddBox from "@mui/icons-material/AddBox";
|
import AddBox from "@mui/icons-material/AddBox";
|
||||||
|
|
||||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
import { getDescriptionFromAutomationNode, Namer } from "utils/formatting";
|
||||||
import { validateNode } from "utils/automations";
|
import { validateNode } from "utils/automations";
|
||||||
import { AutomationCondition } from "types/automations/conditions";
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
import { AutomationTrigger } from "types/automations/triggers";
|
import { AutomationTrigger } from "types/automations/triggers";
|
||||||
@@ -13,6 +13,35 @@ import { convertFailuresToSequenceNodeDataProps } from "./util";
|
|||||||
|
|
||||||
import { ButtonNodeMaker } from "../nodes/ButtonNode";
|
import { ButtonNodeMaker } from "../nodes/ButtonNode";
|
||||||
import { CollectionNodeMaker } from "../nodes/CollectionNode";
|
import { CollectionNodeMaker } from "../nodes/CollectionNode";
|
||||||
|
import { DAGGraphUpdater } from "../updater/index";
|
||||||
|
import { AutomationActionData } from "types/automations";
|
||||||
|
|
||||||
|
export function makeCollectionNodeMakerChildProps<
|
||||||
|
NodeType extends keyof AutomationActionData,
|
||||||
|
Node extends AutomationActionData[NodeType][0]
|
||||||
|
>(
|
||||||
|
nodeType: NodeType,
|
||||||
|
node: Node,
|
||||||
|
index: number,
|
||||||
|
stateUpdater: DAGGraphUpdater,
|
||||||
|
namer: Namer
|
||||||
|
) {
|
||||||
|
const failures = validateNode(node, [nodeType]);
|
||||||
|
|
||||||
|
if (failures) {
|
||||||
|
return {
|
||||||
|
enabled: node.enabled ?? true,
|
||||||
|
...stateUpdater.createNodeActions(nodeType, index, {}),
|
||||||
|
...convertFailuresToSequenceNodeDataProps(failures),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
enabled: node.enabled ?? true,
|
||||||
|
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||||
|
...stateUpdater.createNodeActions(nodeType, index, {}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||||
nodes,
|
nodes,
|
||||||
@@ -24,23 +53,15 @@ export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
|||||||
...dims.collection,
|
...dims.collection,
|
||||||
collectionType: "trigger",
|
collectionType: "trigger",
|
||||||
onAddNode: () => stateUpdater.basic.trigger.addNode(null),
|
onAddNode: () => stateUpdater.basic.trigger.addNode(null),
|
||||||
nodes: nodes.map((node, index) => {
|
nodes: nodes.map((node, index) =>
|
||||||
const failures = validateNode(node, ["trigger"]);
|
makeCollectionNodeMakerChildProps(
|
||||||
|
"trigger",
|
||||||
if (failures) {
|
node,
|
||||||
return {
|
index,
|
||||||
enabled: node.enabled ?? true,
|
stateUpdater,
|
||||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
namer
|
||||||
...convertFailuresToSequenceNodeDataProps(failures),
|
)
|
||||||
};
|
),
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
enabled: node.enabled ?? true,
|
|
||||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
|
||||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return outputState;
|
return outputState;
|
||||||
@@ -57,23 +78,15 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
|||||||
collectionType: "condition",
|
collectionType: "condition",
|
||||||
hasInput: !!lastNodeId,
|
hasInput: !!lastNodeId,
|
||||||
onAddNode: () => stateUpdater.basic.condition.addNode(null),
|
onAddNode: () => stateUpdater.basic.condition.addNode(null),
|
||||||
nodes: nodes.map((node, index) => {
|
nodes: nodes.map((node, index) =>
|
||||||
const failures = validateNode(node, ["condition"]);
|
makeCollectionNodeMakerChildProps(
|
||||||
|
"condition",
|
||||||
if (failures) {
|
node,
|
||||||
return {
|
index,
|
||||||
enabled: node.enabled ?? true,
|
stateUpdater,
|
||||||
...stateUpdater.createNodeActions("condition", index, {}),
|
namer
|
||||||
...convertFailuresToSequenceNodeDataProps(failures),
|
)
|
||||||
};
|
),
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
enabled: node.enabled ?? true,
|
|
||||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
|
||||||
...stateUpdater.createNodeActions("condition", index, {}),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
if (lastNodeId && outputState.lastNodeId) {
|
if (lastNodeId && outputState.lastNodeId) {
|
||||||
|
|||||||
@@ -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";
|
||||||
@@ -24,15 +24,19 @@ const { make, componentMeta } = makeStory({
|
|||||||
state,
|
state,
|
||||||
setState
|
setState
|
||||||
);
|
);
|
||||||
const elementData = useAutomationNodes(state, {
|
const elementData = useAutomationNodes(
|
||||||
dims: {
|
state,
|
||||||
...DEFAULT_DIMS,
|
{
|
||||||
flipped: props.flipped,
|
dims: {
|
||||||
|
...DEFAULT_DIMS,
|
||||||
|
flipped: props.flipped,
|
||||||
|
},
|
||||||
|
namer,
|
||||||
|
openModal: setModalState,
|
||||||
|
stateUpdater: updater,
|
||||||
},
|
},
|
||||||
namer,
|
false
|
||||||
openModal: setModalState,
|
);
|
||||||
stateUpdater: updater,
|
|
||||||
});
|
|
||||||
return (
|
return (
|
||||||
<DAGGraphBoard
|
<DAGGraphBoard
|
||||||
modalState={modalState}
|
modalState={modalState}
|
||||||
|
|||||||
@@ -28,52 +28,57 @@ import * as helpers from "./helpers";
|
|||||||
|
|
||||||
export const useAutomationNodes = (
|
export const useAutomationNodes = (
|
||||||
automation: AutomationActionData,
|
automation: AutomationActionData,
|
||||||
args: ElementMakerBaseProps
|
args: ElementMakerBaseProps,
|
||||||
|
hideConditionAndTriggers: boolean
|
||||||
) => {
|
) => {
|
||||||
const dims: DAGDims = {
|
const dims: DAGDims = {
|
||||||
...args.dims,
|
...args.dims,
|
||||||
};
|
};
|
||||||
const state = useDAGElementsState();
|
const state = useDAGElementsState();
|
||||||
const outputState = new DAGElementsOutputState(dims.position, dims);
|
const outputState = new DAGElementsOutputState(dims.position, dims);
|
||||||
outputState.extend(
|
let actionStartPos = dims.position;
|
||||||
helpers.makeTriggerNodes(automation.trigger, {
|
if (!hideConditionAndTriggers) {
|
||||||
...args,
|
outputState.extend(
|
||||||
state,
|
helpers.makeTriggerNodes(automation.trigger, {
|
||||||
|
...args,
|
||||||
|
state,
|
||||||
|
dims,
|
||||||
|
position: dims.position,
|
||||||
|
nodeId: `${dims.flipped}-trigger`,
|
||||||
|
nodeIndex: 0,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
outputState.extend(
|
||||||
|
helpers.makeConditionNodes(automation.condition, {
|
||||||
|
...args,
|
||||||
|
state,
|
||||||
|
dims,
|
||||||
|
position: distance.moveFromTo(
|
||||||
|
"collection",
|
||||||
|
"collection",
|
||||||
|
outputState.getLastNodePos(),
|
||||||
|
dims
|
||||||
|
),
|
||||||
|
nodeId: `${dims.flipped}-condition`,
|
||||||
|
nodeIndex: 1,
|
||||||
|
lastNodeId: outputState.lastNodeId,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
actionStartPos = distance.moveFromTo(
|
||||||
|
"collection",
|
||||||
|
"node",
|
||||||
|
outputState.getLastNodePos(),
|
||||||
dims,
|
dims,
|
||||||
position: dims.position,
|
true
|
||||||
nodeId: `${dims.flipped}-trigger`,
|
);
|
||||||
nodeIndex: 0,
|
}
|
||||||
})
|
|
||||||
);
|
|
||||||
outputState.extend(
|
|
||||||
helpers.makeConditionNodes(automation.condition, {
|
|
||||||
...args,
|
|
||||||
state,
|
|
||||||
dims,
|
|
||||||
position: distance.moveFromTo(
|
|
||||||
"collection",
|
|
||||||
"collection",
|
|
||||||
outputState.getLastNodePos(),
|
|
||||||
dims
|
|
||||||
),
|
|
||||||
nodeId: `${dims.flipped}-condition`,
|
|
||||||
nodeIndex: 1,
|
|
||||||
lastNodeId: outputState.lastNodeId,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
outputState.extend(
|
outputState.extend(
|
||||||
makeSequenceNodes(automation.action, {
|
makeSequenceNodes(automation.action, {
|
||||||
...args,
|
...args,
|
||||||
state,
|
state,
|
||||||
dims,
|
dims,
|
||||||
position: distance.moveFromTo(
|
position: actionStartPos,
|
||||||
"collection",
|
|
||||||
"node",
|
|
||||||
outputState.getLastNodePos(),
|
|
||||||
dims,
|
|
||||||
true
|
|
||||||
),
|
|
||||||
nodeId: `${dims.flipped}-action`,
|
nodeId: `${dims.flipped}-action`,
|
||||||
nodeIndex: 2,
|
nodeIndex: 2,
|
||||||
lastNodeId: outputState.lastNodeId,
|
lastNodeId: outputState.lastNodeId,
|
||||||
|
|||||||
@@ -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";
|
||||||
@@ -8,6 +8,7 @@ import { DEFAULT_DIMS } from "./elements/constants";
|
|||||||
import { DAGGraphBoard } from "./board";
|
import { DAGGraphBoard } from "./board";
|
||||||
import { AutomationTrigger } from "types/automations/triggers";
|
import { AutomationTrigger } from "types/automations/triggers";
|
||||||
import { AutomationCondition } from "types/automations/conditions";
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
|
import { TriggerConditionNodeRow } from "./NodesRow";
|
||||||
|
|
||||||
export const DAGAutomationGraph: FC<{
|
export const DAGAutomationGraph: FC<{
|
||||||
action: AutomationSequenceNode[];
|
action: AutomationSequenceNode[];
|
||||||
@@ -17,6 +18,7 @@ export const DAGAutomationGraph: FC<{
|
|||||||
onTriggerUpdate: (t: AutomationTrigger[]) => void;
|
onTriggerUpdate: (t: AutomationTrigger[]) => void;
|
||||||
onConditionUpdate: (c: AutomationCondition[]) => void;
|
onConditionUpdate: (c: AutomationCondition[]) => void;
|
||||||
isFlipped: boolean;
|
isFlipped: boolean;
|
||||||
|
useNodesRow: boolean;
|
||||||
additionalControls?: ReactNode;
|
additionalControls?: ReactNode;
|
||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
const { namer } = useHA();
|
const { namer } = useHA();
|
||||||
@@ -37,6 +39,10 @@ export const DAGAutomationGraph: FC<{
|
|||||||
onUpdate: props.onTriggerUpdate as any,
|
onUpdate: props.onTriggerUpdate as any,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const dims = {
|
||||||
|
...DEFAULT_DIMS,
|
||||||
|
flipped: props.isFlipped,
|
||||||
|
};
|
||||||
const elementData = useAutomationNodes(
|
const elementData = useAutomationNodes(
|
||||||
{
|
{
|
||||||
action: props.action,
|
action: props.action,
|
||||||
@@ -44,26 +50,34 @@ export const DAGAutomationGraph: FC<{
|
|||||||
trigger: props.trigger,
|
trigger: props.trigger,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dims: {
|
dims,
|
||||||
...DEFAULT_DIMS,
|
|
||||||
flipped: props.isFlipped,
|
|
||||||
},
|
|
||||||
namer,
|
namer,
|
||||||
openModal: setModalState,
|
openModal: setModalState,
|
||||||
stateUpdater: updater,
|
stateUpdater: updater,
|
||||||
}
|
},
|
||||||
|
props.useNodesRow
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<DAGGraphBoard
|
<>
|
||||||
modalState={modalState}
|
{props.useNodesRow && (
|
||||||
closeModal={() => setModalState(undefined)}
|
<TriggerConditionNodeRow
|
||||||
state={{
|
trigger={props.trigger}
|
||||||
ready: true,
|
condition={props.condition}
|
||||||
data: {
|
stateUpdater={updater}
|
||||||
elements: elementData,
|
sequenceNodeDims={dims.node}
|
||||||
},
|
/>
|
||||||
}}
|
)}
|
||||||
additionalControls={props.additionalControls}
|
<DAGGraphBoard
|
||||||
/>
|
modalState={modalState}
|
||||||
|
closeModal={() => setModalState(undefined)}
|
||||||
|
state={{
|
||||||
|
ready: true,
|
||||||
|
data: {
|
||||||
|
elements: elementData,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
additionalControls={props.additionalControls}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -13,89 +13,91 @@ 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 & { className?: string }>
|
||||||
onAddNode,
|
> = ({
|
||||||
nodes,
|
onAddNode,
|
||||||
sequenceNode,
|
nodes,
|
||||||
height,
|
sequenceNode,
|
||||||
width,
|
height,
|
||||||
flipped,
|
width,
|
||||||
collectionType,
|
flipped,
|
||||||
onDelete,
|
collectionType,
|
||||||
title,
|
onDelete,
|
||||||
children,
|
title,
|
||||||
}) => {
|
children,
|
||||||
const lang = useLang();
|
className,
|
||||||
const color = convertNodeTypeToSequenceNodeColor(collectionType);
|
}) => {
|
||||||
const nodeColor = useSequenceNodeColor(color);
|
const lang = useLang();
|
||||||
const confirm = useConfirm();
|
const color = convertNodeTypeToSequenceNodeColor(collectionType);
|
||||||
const snackbr = useSnackbar();
|
const nodeColor = useSequenceNodeColor(color);
|
||||||
const trueTile = title ?? collectionType;
|
const confirm = useConfirm();
|
||||||
|
const snackbr = useSnackbar();
|
||||||
|
const trueTile = title ?? collectionType;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="collection-nodes--wrap"
|
className={["collection-nodes--wrap", className ?? ""].join(" ")}
|
||||||
style={
|
style={
|
||||||
{
|
{
|
||||||
"--node-color": nodeColor,
|
"--node-color": nodeColor,
|
||||||
"--node-height": `${height}px`,
|
"--node-height": `${height}px`,
|
||||||
"--node-width": `${width}px`,
|
"--node-width": `${width}px`,
|
||||||
} as any
|
} as any
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="collection-nodes">
|
<div className="collection-nodes">
|
||||||
{!!onDelete && (
|
{!!onDelete && (
|
||||||
<ButtonIcon
|
<ButtonIcon
|
||||||
className="delete-icon"
|
className="delete-icon"
|
||||||
icon={<DeleteForeverIcon />}
|
icon={<DeleteForeverIcon />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
confirm({
|
confirm({
|
||||||
description: `Are you sure you want to delete ${trueTile}?`,
|
description: `Are you sure you want to delete ${trueTile}?`,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
onDelete();
|
||||||
|
snackbr.enqueueSnackbar(lang.get("DELETED"), {
|
||||||
|
variant: "info",
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(() => {
|
.catch(() =>
|
||||||
onDelete();
|
snackbr.enqueueSnackbar(
|
||||||
snackbr.enqueueSnackbar(lang.get("DELETED"), {
|
lang.get("NOT_DELETED_THING", {
|
||||||
|
item: trueTile,
|
||||||
|
}),
|
||||||
|
{
|
||||||
variant: "info",
|
variant: "info",
|
||||||
});
|
}
|
||||||
})
|
)
|
||||||
.catch(() =>
|
);
|
||||||
snackbr.enqueueSnackbar(
|
}}
|
||||||
lang.get("NOT_DELETED_THING", {
|
borderless
|
||||||
item: trueTile,
|
color="secondary"
|
||||||
}),
|
/>
|
||||||
{
|
)}
|
||||||
variant: "info",
|
<span className="collection-nodes--title">
|
||||||
}
|
{prettyName(collectionType)}s
|
||||||
)
|
</span>
|
||||||
);
|
<div className="collection-nodes--inner">
|
||||||
}}
|
{nodes.map((n, i) => (
|
||||||
borderless
|
<SequenceNodeElement
|
||||||
color="secondary"
|
key={i}
|
||||||
|
color={color}
|
||||||
|
flipped={flipped}
|
||||||
|
{...n}
|
||||||
|
{...sequenceNode}
|
||||||
/>
|
/>
|
||||||
)}
|
))}
|
||||||
<span className="collection-nodes--title">
|
|
||||||
{prettyName(collectionType)}s
|
|
||||||
</span>
|
|
||||||
<div className="collection-nodes--inner">
|
|
||||||
{nodes.map((n, i) => (
|
|
||||||
<SequenceNodeElement
|
|
||||||
key={i}
|
|
||||||
color={color}
|
|
||||||
flipped={flipped}
|
|
||||||
{...n}
|
|
||||||
{...sequenceNode}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
|
||||||
{children}
|
|
||||||
<span className="collection-nodes--total">
|
|
||||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
<ButtonIcon className="add" icon={<Add />} onClick={onAddNode} />
|
||||||
|
{children}
|
||||||
|
<span className="collection-nodes--total">
|
||||||
|
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
</div>
|
||||||
};
|
);
|
||||||
|
};
|
||||||
@@ -11,8 +11,6 @@
|
|||||||
width: var(--sequence-node-width);
|
width: var(--sequence-node-width);
|
||||||
min-height: var(--sequence-node-height);
|
min-height: var(--sequence-node-height);
|
||||||
min-width: var(--sequence-node-width);
|
min-width: var(--sequence-node-width);
|
||||||
|
|
||||||
/* outline: 1px dotted white; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sequence-node.disabled .sequence-node--inner {
|
.sequence-node.disabled .sequence-node--inner {
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ export const createDummyUpdater = (): DAGUpdaterInput<any> => ({
|
|||||||
data: [],
|
data: [],
|
||||||
onUpdate: console.warn,
|
onUpdate: console.warn,
|
||||||
});
|
});
|
||||||
// export const createScriptConditionFieldUpdater = (f: ScriptConditionField, )
|
|
||||||
|
|
||||||
export type DAGGraphUpdater = ReturnType<typeof createUpdater>;
|
export type DAGGraphUpdater = ReturnType<typeof createUpdater>;
|
||||||
export type DAGGraphChooseUpdater = ReturnType<
|
export type DAGGraphChooseUpdater = ReturnType<
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -188,16 +188,14 @@ export function InputAutoComplete<T extends Option>(
|
|||||||
const id = getID(option);
|
const id = getID(option);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<SearchItem
|
||||||
<SearchItem
|
key={label + id}
|
||||||
key={label + id}
|
listProps={listProps}
|
||||||
listProps={listProps}
|
id={id}
|
||||||
id={id}
|
label={label}
|
||||||
label={label}
|
searchTerm={inputValue}
|
||||||
searchTerm={inputValue}
|
onlyShowLabel={props.onlyShowLabel}
|
||||||
onlyShowLabel={props.onlyShowLabel}
|
/>
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
@@ -225,12 +223,13 @@ export function InputAutoComplete<T extends Option>(
|
|||||||
)}
|
)}
|
||||||
renderTags={(tagValue, getTagProps) => {
|
renderTags={(tagValue, getTagProps) => {
|
||||||
const inner = (
|
const inner = (
|
||||||
<div className="input-autocomplete--tags">
|
<div className="input-autocomplete--tags" key={"inner"}>
|
||||||
{tagValue.map((option, index) => {
|
{tagValue.map((option, index) => {
|
||||||
const label = getLabel(option);
|
const label = getLabel(option);
|
||||||
const id = getID(option);
|
const id = getID(option);
|
||||||
const tagProps = getTagProps({ index });
|
const tagProps = getTagProps({ index });
|
||||||
tagProps.className += " input-autocomplete--chip";
|
tagProps.className += " input-autocomplete--chip";
|
||||||
|
tagProps.key = tagProps.key ?? index;
|
||||||
return (
|
return (
|
||||||
<Chip
|
<Chip
|
||||||
size="medium"
|
size="medium"
|
||||||
@@ -258,7 +257,11 @@ export function InputAutoComplete<T extends Option>(
|
|||||||
}
|
}
|
||||||
if (props.multiple) {
|
if (props.multiple) {
|
||||||
return (
|
return (
|
||||||
<Badge badgeContent={tagValue.length} color="info">
|
<Badge
|
||||||
|
badgeContent={tagValue.length}
|
||||||
|
color="info"
|
||||||
|
key="badge-wrapper"
|
||||||
|
>
|
||||||
{inner}
|
{inner}
|
||||||
</Badge>
|
</Badge>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const { make, componentMeta } = makeStory({
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
maxWidth: 200,
|
maxWidth: 200,
|
||||||
|
margin: "5em",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<InputEntity
|
<InputEntity
|
||||||
|
|||||||
@@ -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> = [
|
||||||
@@ -127,18 +127,16 @@ export const InputTime: FC<InputTimeProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={["input-time", props.className ?? ""].join(" ")}>
|
<div className={["input-time", props.className ?? ""].join(" ")}>
|
||||||
{/* <InputLabel >{props.label}</InputLabel> */}
|
|
||||||
<div className="input-time--inner">
|
<div className="input-time--inner">
|
||||||
{fields.map((name) => {
|
{fields.map((name, index) => {
|
||||||
const label = prettyName(
|
const label = prettyName(
|
||||||
lang.get(`TIME_UNITS_${name}`.toUpperCase())
|
lang.get(`TIME_UNITS_${name}`.toUpperCase())
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
key={name}
|
key={`${name}-${index}`}
|
||||||
variant="filled"
|
variant="filled"
|
||||||
label={label}
|
label={label}
|
||||||
defaultValue="00"
|
|
||||||
InputProps={{
|
InputProps={{
|
||||||
disabled,
|
disabled,
|
||||||
type: "number",
|
type: "number",
|
||||||
@@ -151,6 +149,7 @@ export const InputTime: FC<InputTimeProps> = (props) => {
|
|||||||
})}
|
})}
|
||||||
{!props.restrictEmpty && (
|
{!props.restrictEmpty && (
|
||||||
<ButtonIcon
|
<ButtonIcon
|
||||||
|
key="disable-btn"
|
||||||
onClick={() => setDisabled(!disabled)}
|
onClick={() => setDisabled(!disabled)}
|
||||||
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
icon={disabled ? <EditIcon /> : <CloseIcon />}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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 }) => {
|
||||||
|
|||||||
Loaded 100 of 135 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user