def test_reverse_sweeping(self):
        """Test it sweeps backwards."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        desk.pixels = MagicMock()
        sweep = Sweep(desk, [0, 255, 0], {"direction": "backwards"})
        sweep.run()

        desk.pixels.assert_has_calls([
            call.__setitem__(5, [0, 255, 0]),
            call.show(),
            call.__setitem__(6, [0, 255, 0]),
            call.show(),
            call.__setitem__(7, [0, 255, 0]),
            call.show(),
            call.__setitem__(8, [0, 255, 0]),
            call.show(),
            call.__setitem__(9, [0, 255, 0]),
            call.show(),
            call.__setitem__(4, [0, 255, 0]),
            call.show(),
            call.__setitem__(3, [0, 255, 0]),
            call.show(),
            call.__setitem__(2, [0, 255, 0]),
            call.show(),
            call.__setitem__(1, [0, 255, 0]),
            call.show(),
            call.__setitem__(0, [0, 255, 0]),
            call.show(),
        ])
Пример #2
0
    def test_converging(self):
        """Test it converges."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        desk.pixels = MagicMock()
        converge = Converge(desk, [0, 255, 0])
        converge.run()

        desk.pixels.assert_has_calls(
            [
                call.__setitem__(0, [0, 255, 0]),
                call.__setitem__(5, [0, 255, 0]),
                call.show(),
                call.__setitem__(1, [0, 255, 0]),
                call.__setitem__(6, [0, 255, 0]),
                call.show(),
                call.__setitem__(2, [0, 255, 0]),
                call.__setitem__(7, [0, 255, 0]),
                call.show(),
                call.__setitem__(3, [0, 255, 0]),
                call.__setitem__(8, [0, 255, 0]),
                call.show(),
                call.__setitem__(4, [0, 255, 0]),
                call.__setitem__(9, [0, 255, 0]),
                call.show(),
            ]
        )
Пример #3
0
class Worker:
    """Worker to process the lighting jobs."""
    def __init__(self):
        """Construct."""
        self.redis = redis.Redis()

        desk_conf = conf["sectors"]
        if "TEST_SECTORS" in os.environ:  # nocov
            desk_conf = json.loads(os.environ["TEST_SECTORS"])

        self.desk = Desk(desk_conf)

    def process(self, job):
        """Process a job."""
        try:
            args = json.loads(job.decode("utf-8"))
            self.desk.light_up(args["colour"], args)

        except json.decoder.JSONDecodeError:  # nocov
            print("Your data is bad")

    def poll(self):
        """If there's a job on the queue, pull it off and process it."""
        data = self.redis.lpop("jobs")
        if data:
            self.process(data)

        else:  # nocov
            sleep(conf["worker"]["interval"])

    def work(self):  # nocov
        """Keep working forever."""
        while True:
            self.poll()
Пример #4
0
    def test_setting_lights(self):
        """Test we can set a light to a colour."""
        desk = Desk({"foo": [[0, 19]]})
        desk[19] = [255, 0, 0]
        desk.show()

        self.assertEqual(desk[19], [255, 0, 0])
Пример #5
0
    def __init__(self):
        """Construct."""
        self.redis = redis.Redis()

        desk_conf = conf["sectors"]
        if "TEST_SECTORS" in os.environ:  # nocov
            desk_conf = json.loads(os.environ["TEST_SECTORS"])

        self.desk = Desk(desk_conf)
    def test_direct_switching(self):
        """Test it direct-switches."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        spot_fill = DirectSwitch(desk, [255, 0, 0], {"delay": 0})
        spot_fill.run()

        self.assertTrue(all(pixel == [255, 0, 0] for pixel in desk.pixels))
Пример #7
0
    def test_caterpillar(self):
        """Test it caterpillars."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        caterpillar = Caterpillar(desk, [255, 0, 0], {"delay": 0})
        caterpillar.run()

        self.assertTrue(all(pixel == [255, 0, 0] for pixel in desk.pixels))
Пример #8
0
    def test_spot_filling(self):
        """Test it spot-fills."""
        desk = Desk({"back-of-desk": [[0, 4]], "monitor": [[9, 7], [6, 5]]})
        spot_fill = SpotFill(desk, [255, 0, 0], {"delay": 0})
        spot_fill.run()

        self.assertTrue(all(pixel == [255, 0, 0] for pixel in desk.pixels))
Пример #9
0
    def test_constructor(self):
        """Test it gets the right data."""
        desk = Desk({"back-of-desk": [[0, 7]], "monitor": [[13, 11], [8, 10]]})

        self.assertEqual(
            desk.sectors, [[0, 1, 2, 3, 4, 5, 6, 7], [13, 12, 11], [8, 9, 10]]
        )
        self.assertEqual(desk.indeces, [0, 1, 2, 3, 4, 5, 6, 7, 13, 12, 11, 8, 9, 10])
Пример #10
0
import os

import redis
from flask import Flask, render_template, request

from light_emitting_desk.desk import Desk
from light_emitting_desk.utils import conf

app = Flask(__name__)
app.redis = redis.Redis()

desk_conf = conf["sectors"]
if "TEST_SECTORS" in os.environ:
    desk_conf = json.loads(os.environ["TEST_SECTORS"])

app.desk = Desk(desk_conf)

mode_names = list(map(lambda x: x["name"], conf["modes"]))


@app.route("/", methods=["GET"])
def index():
    """Root endpoint."""
    if request.accept_mimetypes["text/html"]:
        return render_template(
            "index.html",
            title="LED",
            imports=conf["web"]["imports"],
            modes=conf["modes"],
        )
Пример #11
0
 def test_light_up(self):
     """Test it calls a LightMode."""
     desk = Desk({"foo": [[0, 19]]})
     desk.light_up([0, 0, 255], {"mode": "converge"})
Пример #12
0
 def test_fill(self):
     """Test we can fill all the pixels."""
     desk = Desk({"foo": [[0, 19]]})
     desk.pixels = MagicMock()
     desk.fill([255, 0, 0])
     desk.pixels.assert_has_calls([call.fill([255, 0, 0]), call.show()])