Skip to content

Commit 1f9a41a

Browse files
Plugin documentation #486
1 parent 0135d97 commit 1f9a41a

File tree

14 files changed

+317
-16
lines changed

14 files changed

+317
-16
lines changed

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ v1.20.0 - 2018-xx-xx
2626
- [`#484 <https://github.com/dennissiemensma/dsmr-reader/issues/484>`_] API call om huidige versie terug te geven
2727
- [`#291 <https://github.com/dennissiemensma/dsmr-reader/issues/291>`_] API option to get status info
2828
- [`#485 <https://github.com/dennissiemensma/dsmr-reader/issues/485>`_] Retrieve the current energycontract for the statistics page - helmo
29+
- [`#486 <https://github.com/dennissiemensma/dsmr-reader/issues/486>`_] Plugin documentation
2930

3031

3132

docs/credits.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Please note and respect their licences as well, if any. Credits to the following
7575
- `MySQL <https://www.mysql.com/>`_
7676
- `MariaDB <https://mariadb.org/>`_
7777
- `PostgreSQL <http://www.postgresql.org/>`_
78-
- `Director Responsive Admin <http://web-apps.ninja/director-free-responsive-admin-template/>`_
78+
- Director Responsive Admin template (website is offline)
7979
- Favicon made by `Freepik <http://www.freepik.com/>`_ from `flaticon.com <http://www.flaticon.com/free-icon/eco-energy_25013>`_
8080
- `Real Favicon Generator <http://realfavicongenerator.net>`_
8181
- `Bootstrap-datepicker <http://bootstrap-datepicker.readthedocs.org/>`_
@@ -87,7 +87,6 @@ Please note and respect their licences as well, if any. Credits to the following
8787
- `Full Page Screen Capture <https://chrome.google.com/webstore/detail/full-page-screen-capture/fdpohaocaechififmbbbbbknoalclacl?>`_
8888
- `Buienradar <http://www.buienradar.nl>`_
8989
- `Django REST Framework <http://www.django-rest-framework.org>`_
90-
- `Swagger UI Themes <http://meostrander.com/swagger-ui-themes/>`_
9190

9291

9392
Misc

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DSMR Reader's documentation
1212
settings
1313
retention
1414
api
15+
plugins
1516
mqtt
1617
mindergas
1718
pvoutput

docs/locale/nl/LC_MESSAGES/api.mo

-81 Bytes
Binary file not shown.
-81 Bytes
Binary file not shown.

docs/locale/nl/LC_MESSAGES/credits.mo

0 Bytes
Binary file not shown.

docs/locale/nl/LC_MESSAGES/credits.po

+16-13
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ msgid "`PostgreSQL <http://www.postgresql.org/>`_"
276276
msgstr ""
277277

278278
#: ../../credits.rst:78
279-
msgid ""
280-
"`Director Responsive Admin <http://web-apps.ninja/director-free-"
281-
"responsive-admin-template/>`_"
279+
msgid "Director Responsive Admin template (website is offline)"
282280
msgstr ""
283281

284282
#: ../../credits.rst:79
@@ -329,33 +327,29 @@ msgstr ""
329327
msgid "`Django REST Framework <http://www.django-rest-framework.org>`_"
330328
msgstr ""
331329

332-
#: ../../credits.rst:90
333-
msgid "`Swagger UI Themes <http://meostrander.com/swagger-ui-themes/>`_"
334-
msgstr ""
335-
336-
#: ../../credits.rst:94
330+
#: ../../credits.rst:93
337331
msgid "Misc"
338332
msgstr "Overig"
339333

340-
#: ../../credits.rst:96
334+
#: ../../credits.rst:95
341335
msgid "Dutch Smart Meter reading specifications, data cables, examples and hints:"
342336
msgstr "Dutch Smart Meter reading specifications, data cables, examples and hints:"
343337

344-
#: ../../credits.rst:98
338+
#: ../../credits.rst:97
345339
msgid "`Gé Janssen <http://gejanssen.com/howto/Slimme-meter-uitlezen/>`_"
346340
msgstr ""
347341

348-
#: ../../credits.rst:100
342+
#: ../../credits.rst:99
349343
msgid ""
350344
"`Joost van der Linde (smartmeterdashboard) "
351345
"<http://www.smartmeterdashboard.nl/>`_"
352346
msgstr ""
353347

354-
#: ../../credits.rst:102
348+
#: ../../credits.rst:101
355349
msgid "`SOS Solutions <https://www.sossolutions.nl/>`_"
356350
msgstr ""
357351

358-
#: ../../credits.rst:104
352+
#: ../../credits.rst:103
359353
msgid "`Nico Di Rocco <http://nrocco.github.io/>`_"
360354
msgstr ""
361355

@@ -368,3 +362,12 @@ msgstr ""
368362
#~ msgid "`raoulteeuwen <https://github.com/raoulteeuwen >`_"
369363
#~ msgstr ""
370364

365+
#~ msgid ""
366+
#~ "`Director Responsive Admin <http://web-"
367+
#~ "apps.ninja/director-free-responsive-admin-"
368+
#~ "template/>`_"
369+
#~ msgstr ""
370+
371+
#~ msgid "`Swagger UI Themes <http://meostrander.com/swagger-ui-themes/>`_"
372+
#~ msgstr ""
373+

docs/locale/nl/LC_MESSAGES/mqtt.mo

-81 Bytes
Binary file not shown.
-81 Bytes
Binary file not shown.

docs/locale/nl/LC_MESSAGES/plugins.mo

5.66 KB
Binary file not shown.

docs/locale/nl/LC_MESSAGES/plugins.po

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) 2015 - 2018, Dennis Siemensma
3+
# This file is distributed under the same license as the DSMR Reader
4+
# package.
5+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
6+
#
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: DSMR Reader 1.x\n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"Last-Translator: \n"
12+
"Language: nl\n"
13+
"Language-Team: \n"
14+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=utf-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Generated-By: Babel 2.5.1\n"
19+
"X-Generator: Poedit 1.8.7.1\n"
20+
21+
#: ../../plugins.rst:2
22+
msgid "Plugins/hooks (Do It Yourself)"
23+
msgstr "Plugins/hooks (Doe-Het-Zelf)"
24+
25+
#: ../../plugins.rst:3
26+
msgid ""
27+
"The application allows you to create and add plugins, hooking on certain "
28+
"events triggered."
29+
msgstr ""
30+
"De applicatie staat je toe om plugins te maken en te koppelen, op bepaalde "
31+
"gebeurtenissen."
32+
33+
#: ../../plugins.rst:6
34+
msgid "Contents"
35+
msgstr "Inhoudsopgave"
36+
37+
#: ../../plugins.rst:9
38+
msgid "Configuration"
39+
msgstr "Configuratie"
40+
41+
#: ../../plugins.rst:11
42+
msgid ""
43+
"You can create plugins in their own file in ``dsmr_plugins/modules/"
44+
"plugin_name.py``, where ``plugin_name`` is the name of your plugin."
45+
msgstr ""
46+
"Je kan plugins maken in hun eigen bestand in ``dsmr_plugins/modules/"
47+
"plugin_naam.py``, waar ``plugin_naam`` de naam van je plugin is."
48+
49+
#: ../../plugins.rst:14
50+
msgid "Please make sure the ``plugin_name``,"
51+
msgstr "Zorg er voor dat ``plugin_naam``,"
52+
53+
#: ../../plugins.rst:16
54+
msgid "is lowercase (``plugin_name`` and **not** ``PLUGIN_NAME``),"
55+
msgstr "zonder hoofdletters is (``plugin_naam`` en **niet** ``PLUGIN_NAAM``),"
56+
57+
#: ../../plugins.rst:17
58+
msgid ""
59+
"does not contains spaces or dashes, just use underscores and do not start "
60+
"the name with a digit."
61+
msgstr ""
62+
"geen spaties of koppeltekens bevat, gebruik daarvoor underscores en begin "
63+
"de naam niet met een cijfer."
64+
65+
#: ../../plugins.rst:20
66+
msgid ""
67+
"Add the **dotted** path to the end of your ``dsmrreader/settings.py`` file::"
68+
msgstr ""
69+
"Voeg het **dotted** pad toe aan het einde van je ``dsmrreader/settings.py`` "
70+
"bestand::"
71+
72+
#: ../../plugins.rst:27
73+
msgid ""
74+
"Your plugin file is imported once, so you should make sure to hook any "
75+
"events you want."
76+
msgstr ""
77+
"Je plugin-bestand wordt eenmalig geimporteerd, dus zorg ervoor dat je "
78+
"gebeurtenissen koppelt die je wilt volgen."
79+
80+
#: ../../plugins.rst:29
81+
msgid ""
82+
"And finally, make sure to **reload the application** by deploying it again. "
83+
"You can do that by simply executing the ``post-deploy.sh`` script in the "
84+
"root of the project."
85+
msgstr ""
86+
"En tot slot, zorg ervoor dat je **de applicatie herlaadt** door opnieuw te "
87+
"deployen. Je kunt dat doen door simpelweg ``post-deploy.sh`` uit te voeren, "
88+
"het script in de root van het project."
89+
90+
#: ../../plugins.rst:33
91+
msgid "Events / Signals"
92+
msgstr "Gebeurtenissen / Signalen"
93+
94+
#: ../../plugins.rst:34
95+
msgid ""
96+
"These are either dispatched by the Django framework or the application at "
97+
"some point."
98+
msgstr ""
99+
"Deze worden verstuurd door ofwel het Django framework ofwel de applicatie "
100+
"zelf."
101+
102+
#: ../../plugins.rst:37
103+
msgid "``dsmr_backend.signals.backend_called``"
104+
msgstr "``dsmr_backend.signals.backend_called``"
105+
106+
#: ../../plugins.rst:39
107+
msgid ""
108+
"Called by each iteration of the backend. Please use with caution, as it may "
109+
"block all backend operations when used improperly."
110+
msgstr ""
111+
"Aangeroepen bij elke iteratie van de backend. Gebruik dit terughoudend, "
112+
"gezien het alle backend-acties kan blokkeren wanneer het verkeerd gebruikt "
113+
"wordt."
114+
115+
#: ../../plugins.rst:43
116+
msgid "``dsmr_pvoutput.signals.pvoutput_upload``"
117+
msgstr "``dsmr_pvoutput.signals.pvoutput_upload``"
118+
119+
#: ../../plugins.rst:44
120+
msgid ""
121+
"Called by dsmr_pvoutput just before uploading data to PVOutput. The "
122+
"``data`` kwarg contains the data to be sent."
123+
msgstr ""
124+
"Aangeroepen door dsmr_pvoutput vlak voor het uploaden van gegevens naar "
125+
"PVOutput. De ``data`` kwarg bevat de gegevens die verstuurd worden."
126+
127+
#: ../../plugins.rst:48
128+
msgid "``dsmr_datalogger.signals.raw_telegram``"
129+
msgstr "``dsmr_datalogger.signals.raw_telegram``"
130+
131+
#: ../../plugins.rst:49
132+
msgid ""
133+
"Called by dsmr_datalogger when receiving or reading a telegram string. The "
134+
"``data`` kwarg contains the raw telegram string."
135+
msgstr ""
136+
"Aangeroepen door dsmr_datalogger wanneer er een telegram ontvangen of "
137+
"uitgelezen wordt. De ``data`` kwarg bevat de ruwe string met het telegram."
138+
139+
#: ../../plugins.rst:53
140+
msgid "``django.db.models.signals.post_save``"
141+
msgstr "``django.db.models.signals.post_save``"
142+
143+
#: ../../plugins.rst:54
144+
msgid ""
145+
"Called by Django after saving new records to the database. Can be bound to "
146+
"the ``DayStatistics`` model for example, to process daily statistics "
147+
"elsewhere."
148+
msgstr ""
149+
"Aangeroepen door Django bij het opslaan van nieuwe databaserecords. Kan "
150+
"gekoppeld worden aan bijvoorbeeld het ``DayStatistics`` model, om "
151+
"dagelijkse statistieken ergens anders te verwerken."
152+
153+
#: ../../plugins.rst:58
154+
msgid "Other"
155+
msgstr "Overige"
156+
157+
#: ../../plugins.rst:59
158+
msgid ""
159+
"More signals may be available for use, please be careful when binding "
160+
"Django save-signals as it may impact performance. :doc:`If you need any "
161+
"help or information, please seek contact via Github<contributing>`."
162+
msgstr ""
163+
"Meer signalen/gebeurtenissen zijn beschikbaar voor gebruik, echter wees "
164+
"voorzichtig bij het gebruiken van Django save-signalen, aangezien het de "
165+
"performance kan beïnvloeden. :doc:`Mocht je hulp of informatie nodig "
166+
"hebben, zoek dan contact via Github<contributing>`."
167+
168+
#: ../../plugins.rst:64
169+
msgid "Example: Upload data to second PVOutput account"
170+
msgstr "Voorbeeld: Upload gegevens naar een tweede PVOutput-account"
171+
172+
#: ../../plugins.rst:65
173+
msgid ""
174+
"This is an example of issue `#407 <https://github.com/dennissiemensma/dsmr-"
175+
"reader/issues/407>`_, requesting the feature to upload data to a second "
176+
"PVOuput account."
177+
msgstr ""
178+
"Dit is een voorbeeld van issue `#407 <https://github.com/dennissiemensma/"
179+
"dsmr-reader/issues/407>`_, met het verzoek om gegevens te uploaden naar een "
180+
"tweede PVOutput-account."
181+
182+
#: ../../plugins.rst:68
183+
msgid "Settings file ``dsmrreader/settings.py`` (addition)::"
184+
msgstr "Settings bestand ``dsmrreader/settings.py`` (toevoeging)::"
185+
186+
#: ../../plugins.rst:75
187+
msgid "Plugin file ``dsmr_plugins/modules/pvoutput.py``::"
188+
msgstr "Plugin bestand ``dsmr_plugins/modules/pvoutput.py``::"
189+
190+
#: ../../plugins.rst:101
191+
msgid ""
192+
"Note that the ``XXXXX`` and ``YYYYY`` variables should be replace by your "
193+
"second set of PVOutput API credentials."
194+
msgstr ""
195+
"N.B.: De variablen ``XXXXX`` en ``YYYYY`` zouden vervangen moeten worden "
196+
"met de API-credentials van je tweede PVOutput-account."

docs/plugins.rst

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
Plugins/hooks (Do It Yourself)
2+
==============================
3+
The application allows you to create and add plugins, hooking on certain events triggered.
4+
5+
6+
.. contents::
7+
8+
Configuration
9+
~~~~~~~~~~~~~
10+
11+
You can create plugins in their own file in ``dsmr_plugins/modules/plugin_name.py``,
12+
where ``plugin_name`` is the name of your plugin.
13+
14+
Please make sure the ``plugin_name``,
15+
16+
* is lowercase (``plugin_name`` and **not** ``PLUGIN_NAME``),
17+
* does not contains spaces or dashes, just use underscores and do not start the name with a digit.
18+
19+
20+
Add the **dotted** path to the end of your ``dsmrreader/settings.py`` file::
21+
22+
DSMRREADER_PLUGINS = [
23+
'dsmr_plugins.modules.plugin_name1',
24+
'dsmr_plugins.modules.plugin_name2',
25+
]
26+
27+
Your plugin file is imported once, so you should make sure to hook any events you want.
28+
29+
And finally, make sure to **reload the application** by deploying it again. You can do that by simply executing the ``post-deploy.sh`` script in the root of the project.
30+
31+
32+
Events / Signals
33+
----------------
34+
These are either dispatched by the Django framework or the application at some point.
35+
36+
``dsmr_backend.signals.backend_called``
37+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
Called by each iteration of the backend. Please use with caution, as it may block all backend operations when used improperly.
40+
41+
42+
``dsmr_pvoutput.signals.pvoutput_upload``
43+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
Called by dsmr_pvoutput just before uploading data to PVOutput. The ``data`` kwarg contains the data to be sent.
45+
46+
47+
``dsmr_datalogger.signals.raw_telegram``
48+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
Called by dsmr_datalogger when receiving or reading a telegram string. The ``data`` kwarg contains the raw telegram string.
50+
51+
52+
``django.db.models.signals.post_save``
53+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
Called by Django after saving new records to the database. Can be bound to the ``DayStatistics`` model for example, to process daily statistics elsewhere.
55+
56+
57+
Other
58+
^^^^^
59+
More signals may be available for use, please be careful when binding Django save-signals as it may impact performance.
60+
:doc:`If you need any help or information, please seek contact via Github<contributing>`.
61+
62+
63+
Example: Upload data to second PVOutput account
64+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65+
This is an example of issue `#407 <https://github.com/dennissiemensma/dsmr-reader/issues/407>`_, requesting the feature to upload data to a second PVOuput account.
66+
67+
68+
Settings file ``dsmrreader/settings.py`` (addition)::
69+
70+
DSMRREADER_PLUGINS = [
71+
'dsmr_plugins.modules.pvoutput',
72+
]
73+
74+
75+
Plugin file ``dsmr_plugins/modules/pvoutput.py``::
76+
77+
import requests
78+
79+
from dsmr_pvoutput.models.settings import PVOutputAddStatusSettings
80+
from dsmr_pvoutput.signals import pvoutput_upload
81+
82+
def handle_pvoutput_upload(sender, **kwargs):
83+
print(' - Uploading the same data to PVOutput using plugin: {}'.format(kwargs['data']))
84+
85+
response = requests.post(
86+
PVOutputAddStatusSettings.API_URL,
87+
headers={
88+
'X-Pvoutput-Apikey': 'XXXXX',
89+
'X-Pvoutput-SystemId': 'YYYYY',
90+
},
91+
data=kwargs['data']
92+
)
93+
94+
if response.status_code != 200:
95+
print(' [!] PVOutput upload failed (HTTP {}): {}'.format(response.status_code, response.text))
96+
97+
98+
pvoutput_upload.connect(receiver=handle_pvoutput_upload)
99+
100+
101+
Note that the ``XXXXX`` and ``YYYYY`` variables should be replace by your second set of PVOutput API credentials.

0 commit comments

Comments
 (0)