espark-core 0.4.7__py3-none-any.whl → 0.4.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of espark-core might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: espark-core
3
- Version: 0.4.7
3
+ Version: 0.4.9
4
4
  Summary: The core module of the Espark ESP32-based IoT device management framework.
5
5
  License: MIT
6
6
  Requires-Python: >=3.8
@@ -8,13 +8,14 @@ Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
9
  Requires-Dist: aiomqtt>=2.4.0
10
10
  Requires-Dist: apscheduler>=3.11.1
11
- Requires-Dist: fastapi>=0.124.2
11
+ Requires-Dist: fastapi>=0.124.4
12
12
  Requires-Dist: packaging>=25.0
13
+ Requires-Dist: slack-sdk==3.39.0
13
14
  Requires-Dist: sqlalchemy>=2.0.45
14
15
  Requires-Dist: sqlmodel>=0.0.27
15
16
  Requires-Dist: uvicorn[standard]>=0.38.0
16
17
  Provides-Extra: dev
17
- Requires-Dist: aiosqlite==0.21.0; extra == "dev"
18
+ Requires-Dist: aiosqlite==0.22.0; extra == "dev"
18
19
  Requires-Dist: autopep8==2.3.2; extra == "dev"
19
20
  Requires-Dist: build==1.3.0; extra == "dev"
20
21
  Requires-Dist: fastapi-cli[standard-no-fastapi-cloud-cli]==0.0.16; extra == "dev"
@@ -1,10 +1,10 @@
1
- espark_core-0.4.7.dist-info/licenses/LICENSE,sha256=wkIXJHYIspOGVvn_ajKyLucpIyw9_pO3QExFcNTCY78,1065
1
+ espark_core-0.4.9.dist-info/licenses/LICENSE,sha256=wkIXJHYIspOGVvn_ajKyLucpIyw9_pO3QExFcNTCY78,1065
2
2
  esparkcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- esparkcore/constants.py,sha256=uI0bVa78CZa-ftlyTRMqWSBK275iDB1l8g1TmtJ1FGg,378
3
+ esparkcore/constants.py,sha256=v5D_z1nST50FpA5FvpGYz9rk6wngQleCyFU1wtmk58I,417
4
4
  esparkcore/data/__init__.py,sha256=abMOPq6jC5qOQCl9j7iPDv8iyjzDF-oVd_gW0la5kL4,45
5
5
  esparkcore/data/database.py,sha256=OaJSBDW6Qge-rsKkSIksJXOg3xF_y6LuBew--6uFbG4,532
6
6
  esparkcore/data/models/__init__.py,sha256=9YBRwn7R_aovQjT-ZR64fBm7TPs0dsjoq3LzsUTaRtA,124
7
- esparkcore/data/models/device.py,sha256=HQr941uabovQpyGZ1fOnsBNSU_LVmB7JQIZuDkk1uis,1086
7
+ esparkcore/data/models/device.py,sha256=a1Tfw8xHzDLEiVxANZ-lR2aVaWaWJFa8tZQwHBzDgu0,1135
8
8
  esparkcore/data/models/outbox.py,sha256=r5bgjIbj9H-OsGhE-CWKGRf4Tp88qMvmxPYHNGOApY4,1309
9
9
  esparkcore/data/models/telemetry.py,sha256=OfzGqGj2Y1sdK519sSOEXhfuErHoeEdpy5qmJMIc27A,652
10
10
  esparkcore/data/models/version.py,sha256=h2O_Owx-exx5tiQiiauCSELkUHDx-QZjiIGqFPybT4M,269
@@ -14,19 +14,22 @@ esparkcore/data/repositories/device_repository.py,sha256=P9KK-Ta9MgMdrnct5hbGEoi
14
14
  esparkcore/data/repositories/outbox_repository.py,sha256=PdPyKq2Km4_7732O6HhA4BlV_zBjYF91GkMltNKUovg,1015
15
15
  esparkcore/data/repositories/telemetry_repository.py,sha256=5UBBmY-ugcgP0Xji7cu58_nGt8MWKeHz9DHNVJxk0BY,1116
16
16
  esparkcore/data/repositories/version_repository.py,sha256=QZZX2BpFx1i0oeFJ6j0nZvlZH7cViKU8VERBE8AU3ZY,395
17
+ esparkcore/notifications/__init__.py,sha256=WrdUPsRS0tg2rAhv4aj4eGDekkfAsKjcRPRlT6btzQs,77
18
+ esparkcore/notifications/notifier.py,sha256=d4a8leU-oTwWe7ZTLw-vxfCrYlFnCIvbcXabiXkT6Lc,446
19
+ esparkcore/notifications/slack_notifier.py,sha256=-H-3YYm0CRTV8pZgggrNPJKz6815HTumKvE7VsvvSAA,644
17
20
  esparkcore/routers/__init__.py,sha256=K8-S0hugkQT5DB8i8O5YqeRsu9fGfLep6UQzCIpdgGg,131
18
21
  esparkcore/routers/base_router.py,sha256=t-x8tYZVzBk9bD__9yaGYhm66glq_oM_lAHn0eplM2M,3902
19
22
  esparkcore/routers/device_router.py,sha256=mIBAyTyxl9AF8Os_Sms6Bb0vEvWfljyElbTWEGLo0iU,1172
20
23
  esparkcore/routers/telemetry_router.py,sha256=sLO5-oN73IjdGC_ASNif5xmVZHjka_iLv0BKZ_deZP0,1981
21
- esparkcore/routers/version_router.py,sha256=zoOteeK4Cs-OIk_k2v7vPwpR-OfLBwYhOUhNZjPYfHs,387
24
+ esparkcore/routers/version_router.py,sha256=7HYD6sbGWow3DDvK62RXPZu5Qz8DCTTs7wkksQKBq9c,383
22
25
  esparkcore/schedules/__init__.py,sha256=v5Wy3Cbt2AnudGMGXv_Cyaa10s6NAmP66rDjcMSvf0o,74
23
26
  esparkcore/schedules/outbox.py,sha256=GGANvjkI7w1BdmmVRgKog498ASD_xRN0g8bG6yC_SN4,811
24
27
  esparkcore/schedules/scheduler.py,sha256=aYQXImLZ4tW-hRavn3ObuV3lYjmOZD813YkeG1NsYfY,170
25
28
  esparkcore/services/__init__.py,sha256=RIZOHBfkWn3HsApdA5rH9EZbbXGq0NfiGoOWDO_JX1k,30
26
- esparkcore/services/mqtt.py,sha256=Ey2pEkG8sTgX7MQqX1z3Y_5ATwBnacJuf18F_u59_lg,6575
29
+ esparkcore/services/mqtt.py,sha256=EFRVT7QYEpWFhTopS2T6J5O69NWbxeuBQnytCjvd23k,6379
27
30
  esparkcore/utils/__init__.py,sha256=rzuCJUAaQl-yPhM1vcWB_1zVXqtA71ChYP2aM_3UfKk,42
28
31
  esparkcore/utils/logging.py,sha256=sRO8uOcPkFH-DwepqLOTS2qGaopXpMdVOjzZL6RpGs4,257
29
- espark_core-0.4.7.dist-info/METADATA,sha256=faFvfPL1qF0ika4MKD-VbLFL8ZTis3XAmk5zHr7HQeE,6296
30
- espark_core-0.4.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- espark_core-0.4.7.dist-info/top_level.txt,sha256=hXVyhIPB4aGskFm5queWALxDPhcDkrN7_8vcjwA1iE4,11
32
- espark_core-0.4.7.dist-info/RECORD,,
32
+ espark_core-0.4.9.dist-info/METADATA,sha256=kCGaK8PkyR5DMoJCxhwk56RN4sz91l9lJS5CW-bB2xo,6329
33
+ espark_core-0.4.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
+ espark_core-0.4.9.dist-info/top_level.txt,sha256=hXVyhIPB4aGskFm5queWALxDPhcDkrN7_8vcjwA1iE4,11
35
+ espark_core-0.4.9.dist-info/RECORD,,
esparkcore/constants.py CHANGED
@@ -1,6 +1,7 @@
1
1
  ENV_DATABASE_URL : str = 'DATABASE_URL'
2
2
  ENV_MQTT_HOST : str = 'MQTT_HOST'
3
3
  ENV_MQTT_PORT : str = 'MQTT_PORT'
4
+ ENV_UPLOAD_PATH : str = 'UPLOAD_PATH'
4
5
 
5
6
  TOPIC_ACTION : str = 'espark/action'
6
7
  TOPIC_DEVICE : str = 'espark/device'
@@ -8,7 +8,7 @@ from sqlmodel import SQLModel, Field, JSON
8
8
  class Device(SQLModel, table=True):
9
9
  id : str = Field(primary_key=True, description='Unique identifier for the device')
10
10
  display_name : Optional[str] = Field(default=None, description='Human-readable name of the device')
11
- app_name : Optional[str] = Field(default=None, description='Name of the application running on the device')
11
+ app_name : Optional[str] = Field(default=None, foreign_key='appversion.id', ondelete='CASCADE', description='Name of the application running on the device')
12
12
  app_version : Optional[str] = Field(default=None, description='Version of the application running on the device')
13
13
  capabilities : Optional[str] = Field(default=None, description='Comma separated capabilities of the device')
14
14
  parameters : Dict[str, str | int | bool] = Field(default_factory=dict, sa_column=Column(JSON), description='JSON string of capability-specific parameters')
@@ -0,0 +1,2 @@
1
+ from .notifier import BaseNotifier
2
+ from .slack_notifier import SlackNotifier
@@ -0,0 +1,14 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class BaseNotifier(ABC):
5
+ @abstractmethod
6
+ async def notify(self, device_id: str, event_type: str, value: int) -> None:
7
+ """
8
+ Send a notification for an event.
9
+
10
+ Args:
11
+ device_id: ID of the device generating the event.
12
+ event_type: Type of the event (human presence, door open, etc).
13
+ value: An integer value associated with the event.
14
+ """
@@ -0,0 +1,17 @@
1
+ from slack_sdk import WebClient
2
+
3
+ from ..utils import log_debug
4
+ from .notifier import BaseNotifier
5
+
6
+
7
+ class SlackNotifier(BaseNotifier):
8
+ def __init__(self, slack_token: str, slack_channel: str) -> None:
9
+ self.slack_token = slack_token
10
+ self.slack_channel = slack_channel
11
+
12
+ async def notify(self, device_id: str, event_type: str, value: int) -> None:
13
+ client = WebClient(token=self.slack_token)
14
+
15
+ log_debug(f'Posting {event_type} event to Slack for device {device_id}: {value}')
16
+
17
+ client.chat_postMessage(channel=self.slack_channel, text=f'Device {device_id} reported {event_type} with value {value}.')
@@ -7,4 +7,4 @@ class AppVersionRouter(BaseRouter):
7
7
  def __init__(self, repo: AppVersionRepository = None) -> None:
8
8
  self.repo : AppVersionRepository = repo or AppVersionRepository()
9
9
 
10
- super().__init__(AppVersion, self.repo, '/api/v1/versions', ['version'])
10
+ super().__init__(AppVersion, self.repo, '/api/v1/apps', ['version'])
@@ -32,10 +32,7 @@ class MQTTManager:
32
32
  async with async_session() as session:
33
33
  device = await self.device_repo.get(session, Device.id == device_id)
34
34
  if device:
35
- device.app_name = payload['app_name']
36
- device.app_version = payload['app_version']
37
- device.capabilities = payload['capabilities']
38
- device.last_seen = datetime.now(timezone.utc)
35
+ device.last_seen = datetime.now(timezone.utc)
39
36
 
40
37
  await self.device_repo.update(session, device, last_seen=datetime.now(timezone.utc))
41
38
  else: