import multiprocessing
import unicornhathd as unicornhat
import importlib
import sys
import os

import unicornhat
import unicornhathd
import app.programs.original
import app.programs.hd


class State:
    ''' Handles the Unicorn HAT state'''

    def __init__(self, is_hd=True):
        self._process = None
        self.set_model(is_hd)


    def set_model(self, is_hd):
        if is_hd is True:
            self._unicornhat = unicornhathd
            self._app_programs = app.programs.hd
        else:
            self._unicornhat = unicornhat
            self._app_programs = app.programs.original


    def start_program(self, name, params={}):
        try:
            program = getattr(self._app_programs, name)
        except AttributeError:
            raise ProgramNotFound(name)

        self.stop_program()

        if params.get("brightness") is not None:
            self._unicornhat.brightness(float(params["brightness"]))

        if params.get("rotation") is not None:
            self._unicornhat.rotation(int(params["rotation"]))

        self._process = multiprocessing.Process(target=program.run, args=(params,))
        self._process.start()


    def stop_program(self):
        if self._process is not None:
            self._process.terminate()
        self._unicornhat.show()


state = State()


class ProgramNotFound(Exception):
    pass
@@ -878,174 +878,523 @@
     
-self._unicornhat.brightness(float(params%5B%22brightness%22%5D))%0A%0A        if params.get(%22rotation%22) is not None:%0A            self._unicornhat.rotation(int(params%5B%22rotation%22%5D)
+brightness = float(params%5B%22brightness%22%5D)%0A            if 0 %3C= brightness %3C= 1:%0A                self._unicornhat.brightness(brightness)%0A            else:%0A                raise ValueError(%22Brightness must be between 0.0 and 1.0%22)%0A%0A        if params.get(%22rotation%22) is not None:%0A            rotation = int(params%5B%22rotation%22%5D)%0A            if rotation in %5B0, 90, 180, 270%5D:%0A                self._unicornhat.rotation(rotation)%0A            else:%0A                raise ValueError(%22Rotation must be 0, 90, 180 or 270 degrees%22
 )%0A%0A 

Throw errors for brightness and rotation out of bounds, because unicornhathd doesn't do this. Fixes remaining test cases.