second commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
#
|
||||
# encoding: utf-8
|
||||
#import re
|
||||
#from django.utils.translation import gettext_lazy as _
|
||||
from django.conf import settings
|
||||
from django.core.management import BaseCommand
|
||||
from django_celery_beat.models import IntervalSchedule, CrontabSchedule, SolarSchedule
|
||||
from django.contrib.auth import get_user_model
|
||||
from relay import models
|
||||
from modules import utils
|
||||
|
||||
|
||||
def create_user():
|
||||
try:
|
||||
User = get_user_model()
|
||||
if User.objects.count() == 0:
|
||||
for email, username, password, is_superuser in settings.ADMINS:
|
||||
if is_superuser:
|
||||
User.objects.create_superuser(
|
||||
email=email,
|
||||
username=username,
|
||||
password=password,
|
||||
is_active=True,
|
||||
is_superuser=is_superuser,
|
||||
)
|
||||
else:
|
||||
User.objects.create_user(
|
||||
email=email,
|
||||
username=username,
|
||||
password=password,
|
||||
is_active=True,
|
||||
)
|
||||
print(f'Creating {username} user with {password} password and email: {email} superuser: {is_superuser}')
|
||||
except Exception as e:
|
||||
print(f'Creating user error {e}')
|
||||
|
||||
def create_schedule():
|
||||
try:
|
||||
for n in [1, 2, 5, 10, 15, 20, 30, 40, 45, 50]:
|
||||
IntervalSchedule.objects.create(every=n, period='minutes')
|
||||
print('Creating IntervalSchedule minutes')
|
||||
|
||||
for n in [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]:
|
||||
IntervalSchedule.objects.create(every=n, period='hours')
|
||||
print('Creating IntervalSchedule hours')
|
||||
|
||||
for n in [1, 2, 3, 7, 15, 30, 60, 90, 180, 360]:
|
||||
IntervalSchedule.objects.create(every=n, period='days')
|
||||
print('Creating IntervalSchedule days')
|
||||
|
||||
CrontabSchedule.objects.create(minute='0', hour='4', day_of_week='*', timezone=settings.TIME_ZONE)
|
||||
CrontabSchedule.objects.create(minute='0', hour='4', day_of_week='*/3', timezone=settings.TIME_ZONE)
|
||||
CrontabSchedule.objects.create(minute='15', hour='4', day_of_week='*/3', timezone=settings.TIME_ZONE)
|
||||
CrontabSchedule.objects.create(minute='30', hour='4', day_of_week='*/3', timezone=settings.TIME_ZONE)
|
||||
CrontabSchedule.objects.create(minute='0', hour='18', day_of_week='*', timezone=settings.TIME_ZONE)
|
||||
CrontabSchedule.objects.create(minute='15', hour='18', day_of_week='*/3', timezone=settings.TIME_ZONE)
|
||||
CrontabSchedule.objects.create(minute='30', hour='18', day_of_week='*/3', timezone=settings.TIME_ZONE)
|
||||
print('Creating CrontabSchedule')
|
||||
|
||||
SolarSchedule.objects.create(event='sunset', latitude=43.8, longitude=2.3)
|
||||
SolarSchedule.objects.create(event='sunrise', latitude=43.8, longitude=2.3)
|
||||
print('Creating SolarSchedule')
|
||||
|
||||
except Exception as e:
|
||||
print(f'Creating schedule error {e}')
|
||||
|
||||
|
||||
def create_device_type():
|
||||
try:
|
||||
data = dict(
|
||||
name = 'Relais à sortie décalée',
|
||||
code = 'relay_shiftout',
|
||||
)
|
||||
models.DeviceType.objects.create(**data)
|
||||
print(f'Creating DeviceType')
|
||||
except Exception as e:
|
||||
print(f'Creating DeviceType error {e}')
|
||||
|
||||
|
||||
def create_relay():
|
||||
try:
|
||||
device_type = models.DeviceType.objects.filter(code__exact='relay_shiftout').first()
|
||||
for i in range(settings.CTL_RELAY_NUMBER):
|
||||
data = dict(
|
||||
label = f'Relay:{i}',
|
||||
uuid = utils.get_device_uuid(12),
|
||||
device_type = device_type,
|
||||
index = i,
|
||||
)
|
||||
models.Device.objects.create(**data)
|
||||
print('Creating Device', data)
|
||||
|
||||
except Exception as e:
|
||||
print(f'Creating Device error {e}')
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
create_user()
|
||||
create_schedule()
|
||||
create_device_type()
|
||||
create_relay()
|
||||
except Exception as e:
|
||||
print(f'Creating monitor error {e}')
|
||||
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# encoding: utf-8
|
||||
from django.core.management import BaseCommand
|
||||
from django.urls import get_resolver
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **kwargs):
|
||||
|
||||
def show_urls(urllist, depth=0):
|
||||
for entry in urllist:
|
||||
print(entry.pattern)
|
||||
if hasattr(entry, 'url_patterns'):
|
||||
show_urls(entry.url_patterns, depth + 1)
|
||||
|
||||
show_urls(get_resolver().url_patterns)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
'''
|
||||
Created on 19 janv. 2026
|
||||
|
||||
@author: denis
|
||||
'''
|
||||
import os
|
||||
os.environ['BOARD_DEVICE']="RPI"
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
from modules import gpiolib as gpio, devices as dev
|
||||
|
||||
RELAY_KEY = 'Relay_'
|
||||
RELAY_MSG = 'Vanne'
|
||||
# devices
|
||||
DEVICES = []
|
||||
for i in range(settings.RELAY_NUMBER):
|
||||
active = 1
|
||||
DEVICES.append( { 'type': 'RELAY_SHIFTOUT', 'index': i, 'key': f'{RELAY_KEY}{i}', 'label': f'{RELAY_MSG} {i}', 'status': 0, 'active': active, } )
|
||||
|
||||
DEVICES_REGISTERED = DEVICES
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def add_arguments(self, parser):
|
||||
super(Command, self).add_arguments(parser)
|
||||
#parser.add_argument("--task", action="store", dest="task", default='start_all')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
shift_out_register = gpio.ShiftOutRegister74HC595(
|
||||
latch_pin=settings.CTL_LATCH_PIN,
|
||||
clock_pin=settings.CTL_CLOCK_PIN,
|
||||
data_pin=settings.CTL_DATA_PIN,
|
||||
number=settings.CTL_NUMBER,
|
||||
)
|
||||
|
||||
for device in settings.DEVICES_REGISTERED:
|
||||
relay = dev.Relay(shift_out_register, device)
|
||||
relay.relay_start(duration=5)
|
||||
|
||||
except Exception as e:
|
||||
print("Command", e)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# encoding: utf-8
|
||||
from uuid import uuid4
|
||||
from django.core.management import BaseCommand
|
||||
from django.core.management.utils import get_random_string;
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
super().add_arguments(parser)
|
||||
parser.add_argument("--app", type=str, default='django', help=f"Default application django/reductstore")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if options.get('app')=='django':
|
||||
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#€%^&*(-_=+)"
|
||||
|
||||
sk = get_random_string(50, chars)
|
||||
|
||||
print(f'django-insecure-{sk}')
|
||||
elif options.get('app')=='reductstore':
|
||||
print(f'monitor-{uuid4()}')
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
'''
|
||||
Created on 19 janv. 2026
|
||||
|
||||
@author: denis
|
||||
'''
|
||||
from django.core.management.base import BaseCommand
|
||||
from relay import tasks as relay_tasks
|
||||
from home import tasks as mqtt_tasks
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Démarre les tâches Celery."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
super(Command, self).add_arguments(parser)
|
||||
#parser.add_argument("--task", action="store", dest="task", default='start_all')
|
||||
|
||||
def handle(self, *args, **options): # @UnusedVariable
|
||||
#task = options['task']
|
||||
try:
|
||||
mqtt_tasks.start_mqtt_worker.delay() # @UndefinedVariable
|
||||
print("task start_mqtt_worker ...")
|
||||
|
||||
relay_tasks.relay_start_all.delay() # @UndefinedVariable
|
||||
print("task relay_start_all ...")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
Reference in New Issue
Block a user