mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-09 16:18:00 -05:00
make the connectors form be able to display all types for connectors
This commit is contained in:
@@ -12,14 +12,15 @@ from typing import List, Any, Dict, Optional
|
||||
from django_scopes import scope
|
||||
|
||||
from cookbook.connectors.connector import Connector
|
||||
from cookbook.connectors.example import Example
|
||||
from cookbook.connectors.homeassistant import HomeAssistant
|
||||
from cookbook.models import ShoppingListEntry, Recipe, MealPlan, Space, HomeAssistantConfig, ConnectorConfig
|
||||
from cookbook.models import ShoppingListEntry, Recipe, MealPlan, Space, HomeAssistantConfig, ExampleConfig
|
||||
|
||||
multiprocessing.set_start_method('fork') # https://code.djangoproject.com/ticket/31169
|
||||
|
||||
QUEUE_MAX_SIZE = 25
|
||||
REGISTERED_CLASSES: UnionType = ShoppingListEntry | Recipe | MealPlan
|
||||
CONNECTOR_UPDATE_CLASSES: UnionType = HomeAssistantConfig | ConnectorConfig
|
||||
CONNECTOR_UPDATE_CLASSES: UnionType = HomeAssistantConfig | ExampleConfig
|
||||
|
||||
|
||||
class ActionType(Enum):
|
||||
@@ -97,7 +98,10 @@ class ConnectorManager:
|
||||
loop.run_until_complete(close_connectors(connectors))
|
||||
|
||||
with scope(space=space):
|
||||
connectors: List[Connector] = [HomeAssistant(config) for config in space.homeassistantconfig_set.all() if config.enabled]
|
||||
connectors: List[Connector] = [
|
||||
*(HomeAssistant(config) for config in space.homeassistantconfig_set.all() if config.enabled),
|
||||
*(Example(config) for config in space.exampleconfig_set.all() if config.enabled)
|
||||
]
|
||||
_connectors[space.name] = connectors
|
||||
|
||||
if len(connectors) == 0 or refresh_connector_cache:
|
||||
|
||||
27
cookbook/connectors/example.py
Normal file
27
cookbook/connectors/example.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from cookbook.connectors.connector import Connector
|
||||
from cookbook.models import ExampleConfig, Space, ShoppingListEntry
|
||||
|
||||
|
||||
class Example(Connector):
|
||||
_config: ExampleConfig
|
||||
|
||||
def __init__(self, config: ExampleConfig):
|
||||
self._config = config
|
||||
|
||||
async def on_shopping_list_entry_created(self, space: Space, shopping_list_entry: ShoppingListEntry) -> None:
|
||||
if not self._config.on_shopping_list_entry_created_enabled:
|
||||
return
|
||||
pass
|
||||
|
||||
async def on_shopping_list_entry_updated(self, space: Space, shopping_list_entry: ShoppingListEntry) -> None:
|
||||
if not self._config.on_shopping_list_entry_updated_enabled:
|
||||
return
|
||||
pass
|
||||
|
||||
async def on_shopping_list_entry_deleted(self, space: Space, shopping_list_entry: ShoppingListEntry) -> None:
|
||||
if not self._config.on_shopping_list_entry_deleted_enabled:
|
||||
return
|
||||
pass
|
||||
|
||||
async def close(self) -> None:
|
||||
pass
|
||||
Reference in New Issue
Block a user