Exemple #1
0
class Button(models.Model):
    name = models.CharField(max_length=100, null=True)
    x = models.IntegerField()
    y = models.IntegerField()
    icon = models.CharField(max_length=50, choices=ICONS)
    color = models.CharField(max_length=1, choices=COLORS)
    action = models.ForeignKey(Actions, null=True)
    url = models.CharField(max_length=1000, null=True)
    remote = models.ForeignKey(Remote)

    class Meta:
        app_label = 'webmote'
Exemple #2
0
class Remote(models.Model):
    name = models.CharField(max_length=100)
    style = models.IntegerField(choices=STYLES)
    user = models.ForeignKey(User)
    rows = models.IntegerField()

    class Meta:
        app_label = 'webmote'
Exemple #3
0
class IR_Devices(Devices):
    brand = models.CharField(max_length=100, blank=True)
    deviceModelNumber = models.CharField(max_length=100, blank=True)
    remoteModelNumber = models.CharField(max_length=100, blank=True)
    transceiver = models.ForeignKey(Transceivers)

    class Meta:
        app_label = 'webmote'
Exemple #4
0
class Macro(Actions):
    before = models.ForeignKey('self', null=True, related_name='macro_before')
    after = models.ForeignKey('self', null=True, related_name='macro_after')
    action = models.ForeignKey(Actions, null=True, related_name='macro_action')
    delay = models.IntegerField(default=1)
    visible = models.BooleanField(default=False)

    class Meta:
        app_label = 'webmote'

    def runAction(self):
        if self.action:
            self.action.runAction()

        time.sleep(float(self.delay))

        if self.after:
            self.after.runAction()
Exemple #5
0
class Schedlet(models.Model):
    schedule = models.ForeignKey(Schedules)
    action = models.ForeignKey(Actions, related_name='schedlet_action')
    time = models.TimeField()
    sunday = models.BooleanField()
    monday = models.BooleanField()
    tuesday = models.BooleanField()
    wednesday = models.BooleanField()
    thursday = models.BooleanField()
    friday = models.BooleanField()
    saturday = models.BooleanField()

    class Meta:
        app_label = 'webmote'

    def save(self, *args, **kwargs):
        super(Schedlet, self).save(*args, **kwargs)
        # the port number here should be obtained dynamically
        cmd = 'wget http://localhost:8081/scheduler/runSchedlet/' + str(
            self.id) + '/'
        tab = CronTab()
        job = tab.new(command=cmd, comment='Generated by Webmote')
        job.minute.on(self.time.minute)
        job.hour.on(self.time.hour)
        days = (self.sunday, self.monday, self.tuesday, self.wednesday,
                self.thursday, self.friday, self.saturday)
        for (num, day) in enumerate(days):
            if day:
                job.dow.on(num)
                tab.write()

    def delete(self, *args, **kwargs):
        # the port number here should be obtained dynamically
        cmd = 'wget http://localhost:8081/scheduler/runSchedlet/' + str(
            self.id) + '/'
        tab = CronTab()
        job = tab.find_command(cmd)
        if job:
            tab.remove_all(cmd)
        tab.write()
        super(Schedlet, self).delete(*args, **kwargs)
Exemple #6
0
class X10_Devices(Devices):
    house = models.CharField(max_length=1)
    unit = models.IntegerField()
    state = models.IntegerField(default=0)
    lastCommand = models.IntegerField(null=True)
    transceiver = models.ForeignKey(Transceivers)

    class Meta:
        app_label = 'webmote'

    def save(self, *args, **kwargs):
        super(X10_Devices, self).save(*args, **kwargs)
        for command in COMMAND_CODES:
            newCommand = X10_Actions(name=command,
                                     device=self,
                                     code=COMMAND_CODES[command])
            newCommand.save()