From f40f7187de0e042f5a70ef78d27b2fbaa0f46560 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Mon, 1 Jul 2019 20:39:32 +0200 Subject: [PATCH] Add Camera, LOTS project temporal devices --- .../resources/device/definitions.py | 35 ++++++++++++++++ ereuse_devicehub/resources/device/models.py | 40 ++++++++++++++++++- ereuse_devicehub/resources/device/models.pyi | 24 ++++++++++- ereuse_devicehub/resources/device/schemas.py | 38 ++++++++++++++++++ ereuse_devicehub/resources/enums.py | 6 +++ 5 files changed, 141 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/device/definitions.py b/ereuse_devicehub/resources/device/definitions.py index b2cef967..52ca3675 100644 --- a/ereuse_devicehub/resources/device/definitions.py +++ b/ereuse_devicehub/resources/device/definitions.py @@ -166,6 +166,11 @@ class BatteryDef(ComponentDef): SCHEMA = schemas.Battery +class CameraDef(ComponentDef): + VIEW = None + SCHEMA = schemas.Camera + + class ComputerAccessoryDef(DeviceDef): VIEW = None SCHEMA = schemas.ComputerAccessory @@ -297,6 +302,36 @@ class Mixer(CookingDef): SCHEMA = schemas.Mixer +class DrillDef(DeviceDef): + VIEW = None + SCHEMA = schemas.Drill + + +class PackOfScrewdriversDef(DeviceDef): + VIEW = None + SCHEMA = schemas.PackOfScrewdrivers + + +class DehumidifierDef(DeviceDef): + VIEW = None + SCHEMA = schemas.Dehumidifier + + +class StairsDef(DeviceDef): + VIEW = None + SCHEMA = schemas.Stairs + + +class BikeDef(DeviceDef): + VIEW = None + SCHEMA = schemas.Bike + + +class RacketDef(DeviceDef): + VIEW = None + SCHEMA = schemas.Racket + + class ManufacturerDef(Resource): VIEW = ManufacturerView SCHEMA = schemas.Manufacturer diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index f15da040..51364bf8 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -24,7 +24,7 @@ from teal.marshmallow import ValidationError from teal.resource import url_for_resource from ereuse_devicehub.db import db -from ereuse_devicehub.resources.enums import BatteryTechnology, ComputerChassis, \ +from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \ DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing @@ -686,6 +686,18 @@ class Battery(JoinedComponentTableMixin, Component): return real_size / self.size if real_size and self.size else None +class Camera(Component): + """The camera of a device.""" + focal_length = db.Column(db.SmallInteger) + video_height = db.Column(db.SmallInteger) + video_width = db.Column(db.Integer) + horizontal_view_angle = db.Column(db.Integer) + facing = db.Column(db.Enum(CameraFacing)) + vertical_view_angle = db.Column(db.SmallInteger) + video_stabilization = db.Column(db.Boolean) + flash = db.Column(db.Boolean) + + class ComputerAccessory(Device): """Computer peripherals and similar accessories.""" id = Column(BigInteger, ForeignKey(Device.id), primary_key=True) @@ -775,6 +787,32 @@ class Mixer(Cooking): pass +class Drill(Device): + max_drill_bit_size = db.Column(db.SmallInteger) + + +class PackOfScrewdrivers(Device): + pass + + +class Dehumidifier(Device): + size = db.Column(db.SmallInteger) + size.comment = """The capacity in Liters.""" + + +class Stairs(Device): + max_allowed_weight = db.Column(db.Integer) + + +class Bike(Device): + wheel_size = db.Column(db.SmallInteger) + gears = db.Column(db.SmallInteger) + + +class Racket(Device): + pass + + class Manufacturer(db.Model): """The normalized information about a manufacturer. diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index ab75fd23..76bae791 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -14,7 +14,7 @@ from teal.enums import Layouts from ereuse_devicehub.resources.action import models as e from ereuse_devicehub.resources.agent.models import Agent from ereuse_devicehub.resources.device import states -from ereuse_devicehub.resources.enums import BatteryTechnology, ComputerChassis, \ +from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \ DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.models import Thing @@ -356,6 +356,28 @@ class Battery(Component): self.size = ... # type: bool +class Camera(Component): + focal_length = ... # type: Column + video_height = ... # type: Column + video_width = ... # type: Column + horizontal_view_angle = ... # type: Column + facing = ... # type: Column + vertical_view_angle = ... # type: Column + video_stabilization = ... # type: Column + flash = ... # type: Column + + def __init__(self, **kwargs) -> None: + super().__init__(**kwargs) + focal_length = ... # type: Optional[int] + video_height = ... # type: Optional[int] + video_width = ... # type: Optional[int] + horizontal_view_angle = ... # type: Optional[int] + facing = ... # type: Optional[CameraFacing] + vertical_view_angle = ... # type: Optional[int] + video_stabilization = ... # type: Optional[bool] + flash = ... # type: Optional[bool] + + class ComputerAccessory(Device): pass diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index ddd69400..d2b5b4d1 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -307,6 +307,19 @@ class Battery(Component): size = Integer(required=True, description=m.Battery.size.comment) +class Camera(Component): + __doc__ = m.Camera + + focal_length = Integer(data_key='focalLength') + video_height = Integer(data_key='videoHeight') + video_width = Integer(data_key='videoWidth') + horizontal_view_angle = Integer(data_key='horizontalViewAngle') + facing = Integer() + vertical_view_angle = Integer(data_key='verticalViewAngle') + video_stabilization = Integer(data_key='videoStabilization') + flash = Integer() + + class Manufacturer(Schema): __doc__ = m.Manufacturer.__doc__ @@ -398,3 +411,28 @@ class Cooking(Device): class Mixer(Cooking): __doc__ = m.Mixer.__doc__ + + +class Drill(Device): + max_drill_bit_size = Integer(data_key='maxDrillBitSize') + + +class PackOfScrewdrivers(Device): + size = Integer() + + +class Dehumidifier(Device): + size = Integer() + + +class Stairs(Device): + max_allowed_weight = Integer(data_key='maxAllowedWeight') + + +class Bike(Device): + wheel_size = Integer(data_key='wheelSize') + gears = Integer() + + +class Racket(Device): + pass diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index f7571025..f5155eb9 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -249,6 +249,12 @@ class PrinterTechnology(Enum): Thermal = 'Thermal' +@unique +class CameraFacing(Enum): + Front = 'Front' + Back = 'Back' + + @unique class BatteryHealth(Enum): """The battery health status as in Android."""