Beispiel #1
0
def _cleanup() -> None:
    LOG.debug("cleanup")
    composite_disposable = INJECTOR.get(CompositeDisposable)
    composite_disposable.dispose()
    database = INJECTOR.get(SqliteDatabase)
    database.close()
    kraken_repository = INJECTOR.get(KrakenRepository)
    kraken_repository.cleanup()
Beispiel #2
0
def main() -> int:
    LOG.debug("main")
    application: Application = INJECTOR.get(Application)
    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, application.quit)
    exit_status = application.run(sys.argv)
    _cleanup()
    return sys.exit(exit_status)
Beispiel #3
0
    def _load_driver(self) -> None:
        if not self._driver:
            self._driver = INJECTOR.get(Optional[KrakenTwoDriver])

            if self._driver:
                self._driver.initialize()
            else:
                raise ValueError("Kraken USB interface error (check USB cable connection)")
Beispiel #4
0
 def test_driver_none(self, mocker: MockerFixture) -> None:
     # arrange
     mocker.patch.object(DeviceSettings,
                         '__subclasses__',
                         return_value=[SettingsKraken2])
     mocker.patch.object(Kraken2, 'find_supported_devices', return_value=[])
     # act
     driver = INJECTOR.get(Optional[BaseDriver])
     # assert
     assert driver is None
Beispiel #5
0
 def has_supported_kraken(self) -> bool:
     """Checks only if a supported device is found. Connection issues are handled later in the startup process"""
     try:
         self._load_driver()
         return self._driver is not None or INJECTOR.get(
             Optional[BaseDriver]) is not None
     except ValueError:
         # ValueError when no device is found
         return False
     except OSError:
         # OSError when device is found, but the connection fails
         self.cleanup()
         return True
Beispiel #6
0
 def test_driver(self, mocker: MockerFixture) -> None:
     # arrange
     description = 'test device'
     mocker.patch.object(DeviceSettings,
                         '__subclasses__',
                         return_value=[SettingsKraken2])
     mocker.patch.object(Kraken2,
                         'find_supported_devices',
                         return_value=[Kraken2('012345', description)])
     # act
     driver = INJECTOR.get(Optional[BaseDriver])
     # assert
     assert isinstance(driver, Kraken2)
     assert driver.description == description
Beispiel #7
0
 def test_driver_x_vs_z(self, mocker: MockerFixture) -> None:
     # arrange
     mocker.patch.object(DeviceSettings,
                         '__subclasses__',
                         return_value=[SettingsKrakenX3, SettingsKrakenZ3])
     mocker.patch.object(KrakenX3,
                         'find_supported_devices',
                         return_value=[])
     mocker.patch.object(KrakenZ3,
                         'find_supported_devices',
                         return_value=[
                             KrakenZ3('01234', 'test device z', [], []),
                         ])
     # act
     driver = INJECTOR.get(Optional[BaseDriver])
     # assert even though the z driver is a subclass of the x driver, that it correctly pulls the right one
     assert isinstance(driver, KrakenZ3)
     assert isinstance(driver, KrakenX3)
     assert KrakenZ3 is driver.__class__
     assert KrakenX3 is not driver.__class__
Beispiel #8
0
    def _load_driver(self) -> None:
        if not self._driver:
            self._driver = INJECTOR.get(Optional[BaseDriver])

            if isinstance(self._driver, SettingsKrakenLegacy.supported_driver) \
                    and not self._legacy_kraken_warning_issued:
                self._driver = None
                self._legacy_kraken_warning_issued = True
                raise LegacyKrakenWarning(
                    "Aestek potential driver conflict detected. Requires user confirmation to continue."
                )
            if self._driver:
                self._driver.connect()
                init_status: List[Tuple] = self._driver.initialize()
                _LOG.debug("Driver Initialize response: %s", init_status)
                self._init_firmware_version = DeviceSettings.find_firmware(
                    init_status)
            else:
                raise ValueError(
                    "Kraken USB interface error (check USB cable connection)")
Beispiel #9
0
 def test_driver_multiple(self, mocker: MockerFixture) -> None:
     # arrange
     mocker.patch.object(
         DeviceSettings,
         '__subclasses__',
         return_value=[SettingsKrakenZ3, SettingsKrakenX3, SettingsKraken2])
     mocker.patch.object(Kraken2,
                         'find_supported_devices',
                         return_value=[Kraken2('01234', 'test device')])
     mocker.patch.object(
         KrakenX3,
         'find_supported_devices',
         return_value=[KrakenX3('01234', 'test device', [], [])])
     mocker.patch.object(KrakenZ3,
                         'find_supported_devices',
                         return_value=[
                             KrakenZ3('01234', 'test device 1', [], []),
                             KrakenZ3('01234', 'test device 2', [], []),
                         ])
     # act
     driver = INJECTOR.get(Optional[BaseDriver])
     # assert should take the first found device from the first driver in the list of supported_drivers
     assert isinstance(driver, KrakenZ3)
     assert driver.description == 'test device 1'
Beispiel #10
0
 class Meta:
     legacy_table_names = False
     database = INJECTOR.get(SqliteDatabase)
Beispiel #11
0
#
#  You should have received a copy of the GNU General Public License
#  along with gkraken.  If not, see <http://www.gnu.org/licenses/>.

import logging
from typing import Any

from peewee import ForeignKeyField, IntegerField, DateTimeField, SQL, SqliteDatabase
from playhouse.signals import Model, post_save, post_delete

from gkraken.di import INJECTOR, SpeedStepChangedSubject
from gkraken.model.db_change import DbChange
from gkraken.model.speed_profile import SpeedProfile

_LOG = logging.getLogger(__name__)
SPEED_STEP_CHANGED_SUBJECT = INJECTOR.get(SpeedStepChangedSubject)


class SpeedStep(Model):
    profile = ForeignKeyField(SpeedProfile, backref='steps')
    temperature = IntegerField()
    duty = IntegerField()
    timestamp = DateTimeField(constraints=[SQL('DEFAULT CURRENT_TIMESTAMP')])

    class Meta:
        legacy_table_names = False
        database = INJECTOR.get(SqliteDatabase)


@post_save(sender=SpeedStep)
def on_speed_step_added(_: Any, step: SpeedStep, created: bool) -> None:
Beispiel #12
0
# pylint: disable=too-many-locals,too-many-instance-attributes
import logging
from enum import Enum
from typing import Optional, Any

from playhouse.signals import Model, post_save, post_delete
from playhouse.sqlite_ext import AutoIncrementField
from peewee import CharField, DateTimeField, SqliteDatabase, SQL, IntegerField, Check, \
    ForeignKeyField, BooleanField, BlobField

from gkraken.conf import FAN_MIN_DUTY, PUMP_MIN_DUTY
from gkraken.di import INJECTOR, SpeedProfileChangedSubject, SpeedStepChangedSubject

LOG = logging.getLogger(__name__)
SPEED_PROFILE_CHANGED_SUBJECT = INJECTOR.get(SpeedProfileChangedSubject)
SPEED_STEP_CHANGED_SUBJECT = INJECTOR.get(SpeedStepChangedSubject)


class Status:
    def __init__(self, liquid_temperature: float, fan_rpm: int, pump_rpm: int,
                 firmware_version: str) -> None:
        self.liquid_temperature: float = liquid_temperature
        self.fan_rpm: int = fan_rpm
        self.fan_duty: Optional[float] = None
        self.pump_rpm: int = pump_rpm
        self.firmware_version: str = firmware_version


class DbChange:
    INSERT = 0
 class Meta:
     primary_key = CompositeKey('channel', 'index')
     legacy_table_names = False
     database = INJECTOR.get(SqliteDatabase)
Beispiel #14
0
 def has_supported_kraken(self) -> bool:
     return self._driver is not None or INJECTOR.get(
         Optional[KrakenTwoDriver]) is not None