From f60c8a8501bd43b008134ffb4c387ee8bcdf8118 Mon Sep 17 00:00:00 2001 From: Kenny Mochizuki Date: Thu, 27 Jun 2024 01:12:07 -0600 Subject: [PATCH 1/5] 3.0.10 --- CHANGELOG.md | 4 + layrz_sdk/entities/broadcasts/request.py | 19 ++-- layrz_sdk/entities/broadcasts/response.py | 19 ++-- layrz_sdk/entities/broadcasts/result.py | 24 ++-- layrz_sdk/entities/broadcasts/service.py | 17 ++- layrz_sdk/entities/broadcasts/status.py | 19 ++-- layrz_sdk/entities/cases/case.py | 63 ++++++----- layrz_sdk/entities/cases/comment.py | 20 ++-- layrz_sdk/entities/cases/trigger.py | 19 ++-- layrz_sdk/entities/charts/alignment.py | 17 +-- layrz_sdk/entities/charts/bar.py | 76 +++++-------- layrz_sdk/entities/charts/color.py | 22 ++-- layrz_sdk/entities/charts/column.py | 79 +++++-------- layrz_sdk/entities/charts/configuration.py | 23 ++-- layrz_sdk/entities/charts/data_type.py | 17 +-- layrz_sdk/entities/charts/exceptions.py | 23 ++-- layrz_sdk/entities/charts/html.py | 11 +- layrz_sdk/entities/charts/line.py | 98 ++++++++-------- layrz_sdk/entities/charts/map.py | 42 +++---- layrz_sdk/entities/charts/number.py | 11 +- layrz_sdk/entities/charts/pie.py | 61 +++++----- layrz_sdk/entities/charts/radar.py | 48 +++----- layrz_sdk/entities/charts/radial_bar.py | 61 +++++----- .../entities/charts/render_technology.py | 17 +-- layrz_sdk/entities/charts/scatter.py | 105 +++++++++-------- layrz_sdk/entities/charts/serie.py | 7 +- layrz_sdk/entities/charts/serie_type.py | 17 +-- layrz_sdk/entities/charts/table.py | 12 +- layrz_sdk/entities/charts/timeline.py | 53 ++++----- layrz_sdk/entities/checkpoints/checkpoint.py | 27 +++-- layrz_sdk/entities/checkpoints/geofence.py | 19 ++-- layrz_sdk/entities/checkpoints/waypoint.py | 26 +++-- layrz_sdk/entities/events/event.py | 28 ++--- layrz_sdk/entities/formatting/text_align.py | 19 ++-- layrz_sdk/entities/general/asset.py | 29 ++--- .../entities/general/asset_operation_mode.py | 17 +-- layrz_sdk/entities/general/custom_field.py | 19 ++-- layrz_sdk/entities/general/device.py | 25 +++-- layrz_sdk/entities/general/sensor.py | 19 ++-- layrz_sdk/entities/general/user.py | 19 ++-- layrz_sdk/entities/repcom/transaction.py | 8 +- layrz_sdk/entities/reports/col.py | 32 +++--- layrz_sdk/entities/reports/format.py | 7 +- layrz_sdk/entities/reports/header.py | 9 +- layrz_sdk/entities/reports/page.py | 23 ++-- layrz_sdk/entities/reports/report.py | 28 ++--- layrz_sdk/entities/reports/row.py | 20 ++-- layrz_sdk/entities/telemetry/message.py | 9 +- layrz_sdk/entities/telemetry/position.py | 25 +++-- layrz_sdk/lcl/core.py | 106 +++++++++--------- pyproject.toml | 3 +- tests/test_lcl.py | 102 ++++++++--------- 52 files changed, 792 insertions(+), 831 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4735ef1..ba96d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.0.10 + +- Removed Self type annotation from all classes + ## 3.0.9 - Added different return data of Report when password is set diff --git a/layrz_sdk/entities/broadcasts/request.py b/layrz_sdk/entities/broadcasts/request.py index 80fca8d..997fb3f 100644 --- a/layrz_sdk/entities/broadcasts/request.py +++ b/layrz_sdk/entities/broadcasts/request.py @@ -1,5 +1,6 @@ -""" Broadcast Result Request data """ -from typing import Dict, List, Self +"""Broadcast Result Request data""" + +from typing import Dict, List class BroadcastRequest: @@ -11,19 +12,19 @@ class BroadcastRequest: - raw : Raw data """ - def __init__(self: Self, json: Dict | List, raw: str) -> None: + def __init__(self, json: Dict | List, raw: str) -> None: self.json = json self.raw = raw @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastRequest(json={self.json}, raw={self.raw})' - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/broadcasts/response.py b/layrz_sdk/entities/broadcasts/response.py index 620430b..2d67434 100644 --- a/layrz_sdk/entities/broadcasts/response.py +++ b/layrz_sdk/entities/broadcasts/response.py @@ -1,5 +1,6 @@ -""" Broadcast Result Response data """ -from typing import Dict, List, Self +"""Broadcast Result Response data""" + +from typing import Dict, List class BroadcastResponse: @@ -11,19 +12,19 @@ class BroadcastResponse: - raw (str): Raw data """ - def __init__(self: Self, json: Dict | List, raw: str) -> str | None | bool: + def __init__(self, json: Dict | List, raw: str) -> str | None | bool: self.json = json self.raw = raw @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastResponse(json={self.json}, raw={self.raw})' - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/broadcasts/result.py b/layrz_sdk/entities/broadcasts/result.py index b2a5c97..c2acf11 100644 --- a/layrz_sdk/entities/broadcasts/result.py +++ b/layrz_sdk/entities/broadcasts/result.py @@ -1,6 +1,6 @@ -""" Broadcast result """ +"""Broadcast result""" + from datetime import datetime -from typing import Self from .request import BroadcastRequest from .response import BroadcastResponse @@ -21,7 +21,7 @@ class BroadcastResult: """ def __init__( - self: Self, + self, service_id: int, asset_id: int, status: BroadcastStatus, @@ -37,15 +37,17 @@ def __init__( self.submitted_at = submitted_at @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'BroadcastResult(service_id={self.service_id}, asset_id={self.asset_id}, status={self.status}, ' +\ - f'request={self.request}, response={self.response}, submitted_at={self.submitted_at})' + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'BroadcastResult(service_id={self.service_id}, asset_id={self.asset_id}, status={self.status}, ' + + f'request={self.request}, response={self.response}, submitted_at={self.submitted_at})' + ) - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/broadcasts/service.py b/layrz_sdk/entities/broadcasts/service.py index 4f04f94..c0844d0 100644 --- a/layrz_sdk/entities/broadcasts/service.py +++ b/layrz_sdk/entities/broadcasts/service.py @@ -1,5 +1,4 @@ -""" Service entity """ -from typing import Self +"""Service entity""" class OutboundService: @@ -11,19 +10,19 @@ class OutboundService: - name : Service Name """ - def __init__(self: Self, pk: int, name: str) -> str | None | bool: + def __init__(self, pk: int, name: str) -> str | None | bool: self.pk = pk self.name = name @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'OutboundService(pk={self.pk}, name={self.name})' - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/broadcasts/status.py b/layrz_sdk/entities/broadcasts/status.py index 901a48a..cf54057 100644 --- a/layrz_sdk/entities/broadcasts/status.py +++ b/layrz_sdk/entities/broadcasts/status.py @@ -1,10 +1,11 @@ -""" Broadcast result Status """ +"""Broadcast result Status""" + from enum import Enum -from typing import Self class BroadcastStatus(Enum): - """ Broadcast result status """ + """Broadcast result status""" + OK = 'OK' BADREQUEST = 'BADREQUEST' INTERNALERROR = 'INTERNALERROR' @@ -13,14 +14,14 @@ class BroadcastStatus(Enum): DISCONNECTED = 'DISCONNECTED' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastStatus.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/cases/case.py b/layrz_sdk/entities/cases/case.py index 27e3e00..3a7bb3b 100644 --- a/layrz_sdk/entities/cases/case.py +++ b/layrz_sdk/entities/cases/case.py @@ -1,29 +1,29 @@ -""" Events entitites """ +"""Events entitites""" from datetime import datetime from enum import Enum -from typing import Self from .trigger import Trigger class CaseStatus(Enum): - """ Case status enum """ + """Case status enum""" + PENDING = 'PENDING' FOLLOWED = 'FOLLOWED' CLOSED = 'CLOSED' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastStatus.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable @@ -31,22 +31,23 @@ class CaseIgnoredStatus(Enum): """ Case ignore status, will define what kind ignore happened. """ + NORMAL = 'NORMAL' IGNORED = 'IGNORED' PRESSET = 'PRESSET' AUTO = 'AUTO' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastStatus.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable @@ -67,7 +68,7 @@ class Case: """ def __init__( - self: Self, + self, pk: int, trigger: Trigger, asset_id: int, @@ -78,7 +79,7 @@ def __init__( status: CaseStatus = CaseStatus.CLOSED, ignored_status: CaseIgnoredStatus = CaseIgnoredStatus.NORMAL, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.trigger = trigger self.asset_id = asset_id @@ -89,29 +90,31 @@ def __init__( self._sequence = sequence self.ignored_status = ignored_status - def get_sequence(self: Self) -> str | None | bool: - """ Sequence getter """ + def get_sequence(self) -> str | None | bool: + """Sequence getter""" if self._sequence is not None: return f'{self.trigger.code}/{self._sequence}' else: return f'GENERIC/{self.pk}' - def set_sequence(self: Self, sequence: int) -> None: - """ Sequence setter """ + def set_sequence(self, sequence: int) -> None: + """Sequence setter""" self._sequence = sequence sequence = property(get_sequence, set_sequence) @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Case(pk={self.pk}, trigger={self.trigger}, asset_id={self.asset_id}, ' +\ - f'comments={len(self.comments)}, opened_at={self.opened_at}, closed_at={self.closed_at})' - - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Case(pk={self.pk}, trigger={self.trigger}, asset_id={self.asset_id}, ' + + f'comments={len(self.comments)}, opened_at={self.opened_at}, closed_at={self.closed_at})' + ) + + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/cases/comment.py b/layrz_sdk/entities/cases/comment.py index a29053b..14ca4e0 100644 --- a/layrz_sdk/entities/cases/comment.py +++ b/layrz_sdk/entities/cases/comment.py @@ -1,6 +1,6 @@ -""" Comment entity """ +"""Comment entity""" + from datetime import datetime -from typing import Self from layrz_sdk.entities.general.user import User @@ -16,22 +16,22 @@ class Comment: - submitted_at : Date of comment submission """ - def __init__(self: Self, pk: int, content: str, user: User, submitted_at: datetime) -> None: - """ Constructor """ + def __init__(self, pk: int, content: str, user: User, submitted_at: datetime) -> None: + """Constructor""" self.pk = pk self.content = content self.user = user self.submitted_at = submitted_at @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'Comment(pk={self.pk}, content="{self.content}", user={self.user}, submitted_at={self.submitted_at})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/cases/trigger.py b/layrz_sdk/entities/cases/trigger.py index e8e2767..52bcff0 100644 --- a/layrz_sdk/entities/cases/trigger.py +++ b/layrz_sdk/entities/cases/trigger.py @@ -1,5 +1,4 @@ -""" Trigger entity """ -from typing import Self +"""Trigger entity""" class Trigger: @@ -12,21 +11,21 @@ class Trigger: - code : Trigger code """ - def __init__(self: Self, pk: int, name: str, code: str) -> None: - """ Constructor """ + def __init__(self, pk: int, name: str, code: str) -> None: + """Constructor""" self.pk = pk self.name = name self.code = code @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'Trigger(pk={self.pk}, name="{self.name}", code="{self.code}")' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/charts/alignment.py b/layrz_sdk/entities/charts/alignment.py index 4b45541..edae181 100644 --- a/layrz_sdk/entities/charts/alignment.py +++ b/layrz_sdk/entities/charts/alignment.py @@ -1,25 +1,26 @@ -""" Chart alignment """ +"""Chart alignment""" + from enum import Enum -from typing import Self class ChartAlignment(Enum): """ Chart Alignment """ + CENTER = 'center' LEFT = 'left' RIGHT = 'right' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ChartAlignment.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/charts/bar.py b/layrz_sdk/entities/charts/bar.py index 2ca6bb9..9613d89 100644 --- a/layrz_sdk/entities/charts/bar.py +++ b/layrz_sdk/entities/charts/bar.py @@ -1,5 +1,6 @@ -""" Bar chart """ -from typing import Any, List, Self +"""Bar chart""" + +from typing import Any, List from .alignment import ChartAlignment from .configuration import AxisConfig @@ -15,7 +16,7 @@ class BarChart: """ def __init__( - self: Self, + self, x_axis: ChartDataSerie, y_axis: List[ChartDataSerie], title: str = 'Chart', @@ -68,7 +69,7 @@ def __init__( self.y_axis_config = y_axis_config def render( - self: Self, + self, technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS, ) -> Any: """ @@ -105,7 +106,7 @@ def render( 'configuration': [f'Unsupported rendering technology {technology.name}'], } - def _render_syncfusion_flutter_charts(self: Self) -> Any: + def _render_syncfusion_flutter_charts(self) -> Any: """ Converts the configuration of the chart to Syncfusion Flutter Charts. """ @@ -117,11 +118,13 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: x_axis = self.x_axis.data[i] values.append({'xAxis': x_axis, 'yAxis': value}) - series.append({ - 'label': serie.label, - 'color': serie.color, - 'values': values, - }) + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'values': values, + } + ) return { 'series': series, @@ -141,7 +144,7 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: }, } - def _render_graphic(self: Self) -> Any: + def _render_graphic(self) -> Any: """ Converts the configuration of the chart to Flutter library graphic. """ @@ -151,16 +154,18 @@ def _render_graphic(self: Self) -> Any: for serie in self.y_axis: for i, value in enumerate(serie.data): x_axis = self.x_axis.data[i] - series.append({ - 'label': serie.label, - 'color': serie.color, - 'category': x_axis, - 'value': value, - }) + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'category': x_axis, + 'value': value, + } + ) return series - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -183,40 +188,21 @@ def _render_apexcharts(self: Self) -> Any: 'xaxis': { 'categories': self.x_axis.data, 'type': self.x_axis.data_type.value, - 'title': { - 'text': self.x_axis.label - } + 'title': {'text': self.x_axis.label}, }, 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } - }, - 'plotOptions': { - 'bar': { - 'horizontal': True, - 'borderRadius': 4 - } - }, - 'dataLabels': { - 'enabled': False + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, + 'plotOptions': {'bar': {'horizontal': True, 'borderRadius': 4}}, + 'dataLabels': {'enabled': False}, 'chart': { 'type': 'bar', - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } - } + 'animations': {'enabled': False}, + 'toolbar': {'show': False}, + 'zoom': {'enabled': False}, + }, } return config diff --git a/layrz_sdk/entities/charts/color.py b/layrz_sdk/entities/charts/color.py index 88732c6..ef00ad4 100644 --- a/layrz_sdk/entities/charts/color.py +++ b/layrz_sdk/entities/charts/color.py @@ -1,10 +1,12 @@ -""" Chart alignment """ +"""Chart alignment""" + from enum import Enum -from typing import Any, Self +from typing import Any class ChartColor(Enum): - """ Chart color list, ideal to use to colorize the series """ + """Chart color list, ideal to use to colorize the series""" + RED = '#F44336' BLUE = '#2196F3' GREEN = '#4CAF50' @@ -18,19 +20,19 @@ class ChartColor(Enum): LIME = '#CDDC39' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ChartColor.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable def get_color_list() -> Any: - """ Get all colors """ + """Get all colors""" return [color.value for color in ChartColor] diff --git a/layrz_sdk/entities/charts/column.py b/layrz_sdk/entities/charts/column.py index bb8fdc3..91fdbcd 100644 --- a/layrz_sdk/entities/charts/column.py +++ b/layrz_sdk/entities/charts/column.py @@ -1,5 +1,6 @@ -""" Column chart """ -from typing import Any, List, Self +"""Column chart""" + +from typing import Any, List from layrz_sdk.helpers import convert_to_rgba @@ -18,7 +19,7 @@ class ColumnChart: """ def __init__( - self: Self, + self, x_axis: ChartDataSerie, y_axis: List[ChartDataSerie], title: str = 'Chart', @@ -71,7 +72,7 @@ def __init__( self.y_axis_config = y_axis_config def render( - self: Self, + self, technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS, ) -> Any: """ @@ -108,7 +109,7 @@ def render( 'configuration': [f'Unsupported {technology}'], } - def _render_syncfusion_flutter_charts(self: Self) -> Any: + def _render_syncfusion_flutter_charts(self) -> Any: """ Converts the configuration of the chart to Syncfusion Flutter Charts. """ @@ -120,11 +121,13 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: x_axis = self.x_axis.data[i] values.append({'xAxis': x_axis, 'yAxis': value}) - series.append({ - 'label': serie.label, - 'color': serie.color, - 'values': values, - }) + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'values': values, + } + ) return { 'series': series, @@ -144,7 +147,7 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: }, } - def _render_graphic(self: Self) -> Any: + def _render_graphic(self) -> Any: """ Converts the configuration of the chart to Flutter library graphic. """ @@ -154,16 +157,18 @@ def _render_graphic(self: Self) -> Any: for serie in self.y_axis: for i, value in enumerate(serie.data): x_axis = self.x_axis.data[i] - series.append({ - 'label': serie.label, - 'color': serie.color, - 'category': x_axis, - 'value': value, - }) + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'category': x_axis, + 'value': value, + } + ) return series - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -213,43 +218,19 @@ def _render_apexcharts(self: Self) -> Any: 'type': self.x_axis.data_type.value, 'title': { 'text': self.x_axis.label, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } - } - }, - 'dataLabels': { - 'enabled': False + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, + }, }, + 'dataLabels': {'enabled': False}, 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } - }, - 'markers': { - 'size': markers - }, - 'fill': { - 'type': 'solid' + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, + 'markers': {'size': markers}, + 'fill': {'type': 'solid'}, 'stroke': stroke, - 'chart': { - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } - } + 'chart': {'animations': {'enabled': False}, 'toolbar': {'show': False}, 'zoom': {'enabled': False}}, } return config diff --git a/layrz_sdk/entities/charts/configuration.py b/layrz_sdk/entities/charts/configuration.py index 53bde4e..22fe537 100644 --- a/layrz_sdk/entities/charts/configuration.py +++ b/layrz_sdk/entities/charts/configuration.py @@ -1,5 +1,4 @@ -""" Charts entities """ -from typing import Self +"""Charts entities""" from .data_type import ChartDataType @@ -9,30 +8,30 @@ class ChartConfiguration: Chart configuration """ - def __init__(self: Self, name: str, description: str) -> None: - """ Constructor """ + def __init__(self, name: str, description: str) -> None: + """Constructor""" self.name = name self.description = description @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ChartConfiguration(name="{self.name}")' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable class AxisConfig: - """ Axis configuration """ + """Axis configuration""" def __init__( - self: Self, + self, label: str = '', measure_unit: str = '', min_value: float = None, diff --git a/layrz_sdk/entities/charts/data_type.py b/layrz_sdk/entities/charts/data_type.py index 21efec3..cbd0728 100644 --- a/layrz_sdk/entities/charts/data_type.py +++ b/layrz_sdk/entities/charts/data_type.py @@ -1,25 +1,26 @@ -""" Chart Data type """ +"""Chart Data type""" + from enum import Enum -from typing import Self class ChartDataType(Enum): """ Chart Data Type """ + STRING = 'STRING' DATETIME = 'DATETIME' NUMBER = 'NUMBER' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ChartDataType.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/charts/exceptions.py b/layrz_sdk/entities/charts/exceptions.py index 479c7b3..62568bf 100644 --- a/layrz_sdk/entities/charts/exceptions.py +++ b/layrz_sdk/entities/charts/exceptions.py @@ -1,5 +1,4 @@ -""" Chart exceptions """ -from typing import Self +"""Chart exceptions""" class ChartException(BaseException): @@ -7,24 +6,24 @@ class ChartException(BaseException): Chart Exception """ - def __init__(self: Self, message: str) -> None: - """ Constructor """ + def __init__(self, message: str) -> None: + """Constructor""" self._message = message @property - def message(self: Self) -> str | None | bool: - """ Message """ + def message(self) -> str | None | bool: + """Message""" return self._message @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ChartException: {self._message}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/charts/html.py b/layrz_sdk/entities/charts/html.py index 3852f2d..ae5ca3d 100644 --- a/layrz_sdk/entities/charts/html.py +++ b/layrz_sdk/entities/charts/html.py @@ -1,5 +1,6 @@ -""" HTML chart """ -from typing import Any, Self +"""HTML chart""" + +from typing import Any, List from .exceptions import ChartException @@ -9,7 +10,7 @@ class HTMLChart: HTML chart configuration """ - def __init__(self: Self, content: str ='

N/A

', title: str ='Chart') -> None: + def __init__(self, content: str = '

N/A

', title: str = 'Chart') -> None: """ Constructor @@ -27,14 +28,14 @@ def __init__(self: Self, content: str ='

N/A

', title: str ='Chart') -> Non raise ChartException('title must be an instance of str') self.title = title - def render(self: Self) -> Any: + def render(self) -> Any: """ Render chart to a Javascript Library. Currently only available for HTML. """ return {'library': 'HTML', 'configuration': self._render_html()} - def _render_html(self: Self) -> Any: + def _render_html(self) -> Any: """ Converts the configuration of the chart to HTML render engine. """ diff --git a/layrz_sdk/entities/charts/line.py b/layrz_sdk/entities/charts/line.py index 20cd514..f86a353 100644 --- a/layrz_sdk/entities/charts/line.py +++ b/layrz_sdk/entities/charts/line.py @@ -1,6 +1,7 @@ -""" Line chart """ +"""Line chart""" + import logging -from typing import Any, List, Self +from typing import Any, List from .alignment import ChartAlignment from .configuration import AxisConfig @@ -20,7 +21,7 @@ class LineChart: """ def __init__( - self: Self, + self, x_axis: ChartDataSerie, y_axis: List[ChartDataSerie], title: str = 'Chart', @@ -72,7 +73,7 @@ def __init__( raise ChartException('y_axis_config must be an instance of AxisConfig') self.y_axis_config = y_axis_config - def render(self: Self, technology: ChartRenderTechnology) -> Any: + def render(self, technology: ChartRenderTechnology) -> Any: """ Render chart to a graphic Library. We have two graphic libraries: GRAPHIC and CANVASJS. @@ -108,7 +109,7 @@ def render(self: Self, technology: ChartRenderTechnology) -> Any: 'configuration': [f'Unsupported {technology}'], } - def _render_syncfusion_flutter_charts(self: Self) -> Any: + def _render_syncfusion_flutter_charts(self) -> Any: """ Converts the configuration of the chart to a Flutter library syncfusion_flutter_charts. """ @@ -134,20 +135,24 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: y_value = 0 if not isinstance(y_value, (int, float)): - log.debug('Value isn\'t a number: %s', y_value) + log.debug("Value isn't a number: %s", y_value) continue - points.append({ - 'xAxis': x_value, - 'yAxis': y_value, - }) - - series.append({ - 'color': serie.color, - 'values': points, - 'label': serie.label, - 'type': 'AREA' if serie.serie_type == ChartDataSerieType.AREA else 'LINE', - }) + points.append( + { + 'xAxis': x_value, + 'yAxis': y_value, + } + ) + + series.append( + { + 'color': serie.color, + 'values': points, + 'label': serie.label, + 'type': 'AREA' if serie.serie_type == ChartDataSerieType.AREA else 'LINE', + } + ) return { 'series': series, @@ -167,7 +172,7 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: }, } - def _render_graphic(self: Self) -> Any: + def _render_graphic(self) -> Any: """ Converts the configuration of the chart to a Flutter library Graphic. """ @@ -180,25 +185,29 @@ def _render_graphic(self: Self) -> Any: points = [] for i, value in enumerate(self.x_axis.data): - points.append({ - 'x_axis': { - 'value': value.timestamp() if self.x_axis.data_type == ChartDataType.DATETIME else value, - 'is_datetime': self.x_axis.data_type == ChartDataType.DATETIME, - }, - 'y_axis': serie.data[i], - }) - - series.append({ - 'group': serie.label, - 'color': serie.color, - 'dashed': serie.serie_type == ChartDataSerieType.LINE and serie.dashed, - 'type': 'AREA' if serie.serie_type == ChartDataSerieType.AREA else 'LINE', - 'values': points - }) + points.append( + { + 'x_axis': { + 'value': value.timestamp() if self.x_axis.data_type == ChartDataType.DATETIME else value, + 'is_datetime': self.x_axis.data_type == ChartDataType.DATETIME, + }, + 'y_axis': serie.data[i], + } + ) + + series.append( + { + 'group': serie.label, + 'color': serie.color, + 'dashed': serie.serie_type == ChartDataSerieType.LINE and serie.dashed, + 'type': 'AREA' if serie.serie_type == ChartDataSerieType.AREA else 'LINE', + 'values': points, + } + ) return series - def _render_canvasjs(self: Self) -> Any: + def _render_canvasjs(self) -> Any: """ Converts the configuration of the chart to Javascript library CanvasJS. """ @@ -236,10 +245,12 @@ def _render_canvasjs(self: Self) -> Any: points.append({'x': point.x, 'y': point.y}) else: for i, value in enumerate(self.x_axis.data): - points.append({ - 'x': (value.timestamp() * 1000) if self.x_axis.data_type == ChartDataType.DATETIME else value, - 'y': serie.data[i], - }) + points.append( + { + 'x': (value.timestamp() * 1000) if self.x_axis.data_type == ChartDataType.DATETIME else value, + 'y': serie.data[i], + } + ) dataset['dataPoints'] = points datasets.append(dataset) @@ -251,7 +262,7 @@ def _render_canvasjs(self: Self) -> Any: 'text': self.title, 'fontFamily': 'Fira Sans Condensed', 'fontSize': 20, - 'horizontalAlign': self.align.value + 'horizontalAlign': self.align.value, }, 'data': datasets, 'axisX': { @@ -259,13 +270,8 @@ def _render_canvasjs(self: Self) -> Any: 'titleFontFamily': 'Fira Sans Condensed', 'titleFontSize': 20, }, - 'toolTip': { - 'animationEnabled': False, - 'shared': True - }, - 'legend': { - 'cursor': 'pointer' - } + 'toolTip': {'animationEnabled': False, 'shared': True}, + 'legend': {'cursor': 'pointer'}, } diff --git a/layrz_sdk/entities/charts/map.py b/layrz_sdk/entities/charts/map.py index 7e2818c..c5ce507 100644 --- a/layrz_sdk/entities/charts/map.py +++ b/layrz_sdk/entities/charts/map.py @@ -1,6 +1,7 @@ -""" Map chart """ +"""Map chart""" + from enum import Enum -from typing import Any, List, Self, Tuple +from typing import Any, List, Tuple from .exceptions import ChartException from .render_technology import ChartRenderTechnology @@ -10,28 +11,29 @@ class MapCenterType(Enum): """ Map Chart center type """ + FIXED = 'FIXED' CONTAIN = 'CONTAIN' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastStatus.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable class MapPoint: - """ Map point configuration """ + """Map point configuration""" def __init__( - self: Self, + self, latitude: float, longitude: float, label: str, @@ -69,7 +71,7 @@ class MapChart: """ def __init__( - self: Self, + self, points: List[MapPoint], title: str = 'Chart', center: MapCenterType = MapCenterType.CONTAIN, @@ -100,7 +102,7 @@ def __init__( raise ChartException('center_latlng must be an instance of list or tuple') self.center_latlng = center_latlng - def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER_MAP) -> Any: + def render(self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER_MAP) -> Any: """ Render chart to a graphic Library. We have two graphic libraries: FLUTTER_MAP and LEAFLET. @@ -121,18 +123,20 @@ def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology 'configuration': [f'Unsupported {technology}'], } - def _render_flutter_map(self: Self) -> Any: + def _render_flutter_map(self) -> Any: """ Converts the configuration to the chart to Flutter Map engine. """ points = [] for point in self.points: - points.append({ - 'label': point.label, - 'color': point.color, - 'latlng': (point.latitude, point.longitude), - }) + points.append( + { + 'label': point.label, + 'color': point.color, + 'latlng': (point.latitude, point.longitude), + } + ) center = 'CONTAIN' @@ -149,7 +153,7 @@ def _render_flutter_map(self: Self) -> Any: return config - def _render_leaflet(self: Self) -> Any: + def _render_leaflet(self) -> Any: """ Converts the configuration of the chart to Leaflet map engine. """ diff --git a/layrz_sdk/entities/charts/number.py b/layrz_sdk/entities/charts/number.py index 6d3f7fd..c7c9c25 100644 --- a/layrz_sdk/entities/charts/number.py +++ b/layrz_sdk/entities/charts/number.py @@ -1,5 +1,6 @@ -""" Number chart """ -from typing import Any, Self +"""Number chart""" + +from typing import Any from .render_technology import ChartRenderTechnology @@ -9,7 +10,7 @@ class NumberChart: Number chart configuration """ - def __init__(self: Self, value: float, color: str, label: str) -> None: + def __init__(self, value: float, color: str, label: str) -> None: """ Constructor @@ -23,7 +24,7 @@ def __init__(self: Self, value: float, color: str, label: str) -> None: self.color = color self.label = label - def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER) -> Any: + def render(self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER) -> Any: """ Render chart to a graphic Library. """ @@ -40,7 +41,7 @@ def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology 'configuration': [f'Unsupported {technology}'], } - def _render_flutter(self: Self) -> Any: + def _render_flutter(self) -> Any: """ Converts the configuration of the chart to a Flutter native components. """ diff --git a/layrz_sdk/entities/charts/pie.py b/layrz_sdk/entities/charts/pie.py index c25b195..93feda9 100644 --- a/layrz_sdk/entities/charts/pie.py +++ b/layrz_sdk/entities/charts/pie.py @@ -1,5 +1,6 @@ -""" Pie chart """ -from typing import Any, List, Self +"""Pie chart""" + +from typing import Any, List from .alignment import ChartAlignment from .exceptions import ChartException @@ -13,7 +14,7 @@ class PieChart: """ def __init__( - self: Self, + self, series: List[ChartDataSerie], title: str = 'Chart', align: ChartAlignment = ChartAlignment.CENTER, @@ -41,7 +42,7 @@ def __init__( self.align = align def render( - self: Self, + self, technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS, ) -> Any: """ @@ -78,37 +79,41 @@ def render( 'configuration': [f'Unsupported {technology}'], } - def _render_syncfusion_flutter_charts(self: Self) -> Any: + def _render_syncfusion_flutter_charts(self) -> Any: """ Converts the configuration of the chart to Syncfusion Flutter Charts. """ series = [] for serie in self.series: - series.append({ - 'label': serie.label, - 'color': serie.color, - 'value': serie.data[0], - }) + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'value': serie.data[0], + } + ) return {'series': series} - def _render_graphic(self: Self) -> Any: + def _render_graphic(self) -> Any: """ Converts the configuration of the chart to a Flutter library Graphic. """ series = [] for serie in self.series: - series.append({ - 'group': serie.label, - 'color': serie.color, - 'value': serie.data[0], - }) + series.append( + { + 'group': serie.label, + 'color': serie.color, + 'value': serie.data[0], + } + ) return series - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -129,27 +134,15 @@ def _render_apexcharts(self: Self) -> Any: 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, 'chart': { 'type': 'pie', - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } + 'animations': {'enabled': False}, + 'toolbar': {'show': False}, + 'zoom': {'enabled': False}, }, - 'dataLabels': { - 'enabled': True - } + 'dataLabels': {'enabled': True}, } return config diff --git a/layrz_sdk/entities/charts/radar.py b/layrz_sdk/entities/charts/radar.py index 552bbd6..ad8bb52 100644 --- a/layrz_sdk/entities/charts/radar.py +++ b/layrz_sdk/entities/charts/radar.py @@ -1,5 +1,6 @@ -""" Radar chart """ -from typing import Any, List, Self +"""Radar chart""" + +from typing import Any, List from .alignment import ChartAlignment from .exceptions import ChartException @@ -14,7 +15,7 @@ class RadarChart: """ def __init__( - self: Self, + self, x_axis: ChartDataSerie, y_axis: List[ChartDataSerie], title: str = 'Chart', @@ -48,14 +49,14 @@ def __init__( raise ChartException('align must be an instance of ChartAlignment') self.align = align - def render(self: Self) -> Any: + def render(self) -> Any: """ Render chart to a Javascript Library. Currently only available for ApexCharts. """ return {'library': 'APEXCHARTS', 'configuration': self._render_apexcharts()} - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -80,43 +81,22 @@ def _render_apexcharts(self: Self) -> Any: 'type': self.x_axis.data_type.value, 'title': { 'text': self.x_axis.label, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } - } + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, + }, }, 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, 'chart': { 'type': 'radar', - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } - }, - 'dataLabels': { - 'enabled': True + 'animations': {'enabled': False}, + 'toolbar': {'show': False}, + 'zoom': {'enabled': False}, }, - 'plotOptions': { - 'bar': { - 'horizontal': True, - 'borderRadius': 4 - } - } + 'dataLabels': {'enabled': True}, + 'plotOptions': {'bar': {'horizontal': True, 'borderRadius': 4}}, } return config diff --git a/layrz_sdk/entities/charts/radial_bar.py b/layrz_sdk/entities/charts/radial_bar.py index 52affa5..b2d9678 100644 --- a/layrz_sdk/entities/charts/radial_bar.py +++ b/layrz_sdk/entities/charts/radial_bar.py @@ -1,5 +1,6 @@ -""" Radial Bar chart """ -from typing import Any, List, Self +"""Radial Bar chart""" + +from typing import Any, List from .alignment import ChartAlignment from .exceptions import ChartException @@ -13,7 +14,7 @@ class RadialBarChart: """ def __init__( - self: Self, + self, series: List[ChartDataSerie], title: str = 'Chart', align: ChartAlignment = ChartAlignment.CENTER, @@ -41,7 +42,7 @@ def __init__( self.align = align def render( - self: Self, + self, technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS, ) -> Any: """ @@ -78,37 +79,41 @@ def render( 'configuration': [f'Unsupported {technology}'], } - def _render_syncfusion_flutter_charts(self: Self) -> Any: + def _render_syncfusion_flutter_charts(self) -> Any: """ Converts the configuration of the chart to Syncfusion Flutter Charts. """ series = [] for serie in self.series: - series.append({ - 'label': serie.label, - 'color': serie.color, - 'value': serie.data[0], - }) + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'value': serie.data[0], + } + ) return {'series': series} - def _render_graphic(self: Self) -> Any: + def _render_graphic(self) -> Any: """ Converts the configuration of the chart to a Flutter library Graphic. """ series = [] for serie in self.series: - series.append({ - 'group': serie.label, - 'color': serie.color, - 'value': serie.data[0], - }) + series.append( + { + 'group': serie.label, + 'color': serie.color, + 'value': serie.data[0], + } + ) return series - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -129,27 +134,15 @@ def _render_apexcharts(self: Self) -> Any: 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, 'chart': { 'type': 'radialBar', - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } - }, - 'dataLabels': { - 'enabled': True + 'animations': {'enabled': False}, + 'toolbar': {'show': False}, + 'zoom': {'enabled': False}, }, + 'dataLabels': {'enabled': True}, } return config diff --git a/layrz_sdk/entities/charts/render_technology.py b/layrz_sdk/entities/charts/render_technology.py index 62b6ad6..a55814b 100644 --- a/layrz_sdk/entities/charts/render_technology.py +++ b/layrz_sdk/entities/charts/render_technology.py @@ -1,12 +1,13 @@ -""" Chart rendering technology / library """ +"""Chart rendering technology / library""" + from enum import Enum -from typing import Self class ChartRenderTechnology(Enum): """ Chart Alignment """ + CANVAS_JS = 'CANVAS_JS' GRAPHIC = 'GRAPHIC' SYNCFUSION_FLUTTER_CHARTS = 'SYNCFUSION_FLUTTER_CHARTS' @@ -15,14 +16,14 @@ class ChartRenderTechnology(Enum): FLUTTER = 'FLUTTER' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ChartRenderTechnology.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/charts/scatter.py b/layrz_sdk/entities/charts/scatter.py index 29871ce..d877f27 100644 --- a/layrz_sdk/entities/charts/scatter.py +++ b/layrz_sdk/entities/charts/scatter.py @@ -1,5 +1,6 @@ -""" Scatter chart """ -from typing import Any, List, Self +"""Scatter chart""" + +from typing import Any, List from .alignment import ChartAlignment from .configuration import AxisConfig @@ -13,7 +14,7 @@ class ScatterSerieItem: Chart Data Serie Item for Scatter Charts """ - def __init__(self: Self, x: float, y: float) -> None: + def __init__(self, x: float, y: float) -> None: """ Constructor @@ -32,7 +33,7 @@ class ScatterSerie: """ def __init__( - self: Self, + self, data: List[ScatterSerieItem], color: str, label: str, @@ -70,7 +71,7 @@ class ScatterChart: """ def __init__( - self: Self, + self, series: List[ScatterSerie], title: str = 'Chart', align: ChartAlignment = ChartAlignment.CENTER, @@ -114,7 +115,7 @@ def __init__( self.y_axis_config = y_axis_config def render( - self: Self, + self, technology: ChartRenderTechnology = ChartRenderTechnology.SYNCFUSION_FLUTTER_CHARTS, ) -> Any: """ @@ -151,7 +152,7 @@ def render( 'configuration': [f'Unsupported {technology}'], } - def _render_syncfusion_flutter_charts(self: Self) -> Any: + def _render_syncfusion_flutter_charts(self) -> Any: """ Converts the configuration of the chart to Flutter library Graphic. """ @@ -175,17 +176,21 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: if not isinstance(item.y, (int, float)): continue - data.append({ - 'xAxis': item.x, - 'yAxis': item.y, - }) - - series.append({ - 'label': serie.label, - 'color': serie.color, - 'values': data, - 'type': type_serie, - }) + data.append( + { + 'xAxis': item.x, + 'yAxis': item.y, + } + ) + + series.append( + { + 'label': serie.label, + 'color': serie.color, + 'values': data, + 'type': type_serie, + } + ) return { 'series': series, @@ -205,7 +210,7 @@ def _render_syncfusion_flutter_charts(self: Self) -> Any: }, } - def _render_graphic(self: Self) -> Any: + def _render_graphic(self) -> Any: """ Converts the configuration of the chart to Flutter library Graphic. """ @@ -224,21 +229,25 @@ def _render_graphic(self: Self) -> Any: continue for item in serie.data: - data.append({ - 'x_axis': item.x, - 'y_axis': item.y, - }) - - series.append({ - 'group': serie.label, - 'color': serie.color, - 'values': data, - 'type': type_serie, - }) + data.append( + { + 'x_axis': item.x, + 'y_axis': item.y, + } + ) + + series.append( + { + 'group': serie.label, + 'color': serie.color, + 'values': data, + 'type': type_serie, + } + ) return series - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -252,11 +261,13 @@ def _render_apexcharts(self: Self) -> Any: for item in serie.data: data.append([item.x, item.y]) - series.append({ - 'name': serie.label, - 'data': data, - 'type': serie.serie_type.value, - }) + series.append( + { + 'name': serie.label, + 'data': data, + 'type': serie.serie_type.value, + } + ) colors.append(serie.color) config = { @@ -265,27 +276,15 @@ def _render_apexcharts(self: Self) -> Any: 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, 'chart': { 'type': 'scatter', - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } + 'animations': {'enabled': False}, + 'toolbar': {'show': False}, + 'zoom': {'enabled': False}, }, - 'dataLabels': { - 'enabled': True - } + 'dataLabels': {'enabled': True}, } return config diff --git a/layrz_sdk/entities/charts/serie.py b/layrz_sdk/entities/charts/serie.py index 9bc44ac..2a3bcb6 100644 --- a/layrz_sdk/entities/charts/serie.py +++ b/layrz_sdk/entities/charts/serie.py @@ -1,5 +1,6 @@ -""" Chart Data Serie """ -from typing import Any, Self +"""Chart Data Serie""" + +from typing import Any from .data_type import ChartDataType from .exceptions import ChartException @@ -12,7 +13,7 @@ class ChartDataSerie: """ def __init__( - self: Self, + self, data: Any, color: str = '#000000', label: str = '', diff --git a/layrz_sdk/entities/charts/serie_type.py b/layrz_sdk/entities/charts/serie_type.py index e6e02e9..1df3237 100644 --- a/layrz_sdk/entities/charts/serie_type.py +++ b/layrz_sdk/entities/charts/serie_type.py @@ -1,26 +1,27 @@ -""" Chart Serie type """ +"""Chart Serie type""" + from enum import Enum -from typing import Self class ChartDataSerieType(Enum): """ Chart data serie type """ + NONE = None LINE = 'line' AREA = 'area' SCATTER = 'scatter' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'BroadcastStatus.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/charts/table.py b/layrz_sdk/entities/charts/table.py index e785ce0..9d3f493 100644 --- a/layrz_sdk/entities/charts/table.py +++ b/layrz_sdk/entities/charts/table.py @@ -1,6 +1,6 @@ """Number chart""" -from typing import Any, List, Self +from typing import Any, List from .render_technology import ChartRenderTechnology @@ -8,7 +8,7 @@ class TableHeader: """Table header chart configuration""" - def __init__(self: Self, label: str, key: str) -> None: + def __init__(self, label: str, key: str) -> None: """Constructor --- Arguments @@ -22,7 +22,7 @@ def __init__(self: Self, label: str, key: str) -> None: class TableRow: """Table row chart configuration""" - def __init__(self: Self, data: Any) -> None: + def __init__(self, data: Any) -> None: """Constructor --- Arguments @@ -36,7 +36,7 @@ class TableChart: Table chart configuration """ - def __init__(self: Self, columns: List[TableHeader], rows: List[TableRow]) -> None: + def __init__(self, columns: List[TableHeader], rows: List[TableRow]) -> None: """ Constructor --- @@ -47,7 +47,7 @@ def __init__(self: Self, columns: List[TableHeader], rows: List[TableRow]) -> No self.columns = columns self.rows = rows - def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER) -> Any: + def render(self, technology: ChartRenderTechnology = ChartRenderTechnology.FLUTTER) -> Any: """ Render chart to a graphic Library. """ @@ -64,7 +64,7 @@ def render(self: Self, technology: ChartRenderTechnology = ChartRenderTechnology 'configuration': [f'Unsupported {technology}'], } - def _render_flutter(self: Self) -> Any: + def _render_flutter(self) -> Any: """ Converts the configuration of the chart to a Flutter native components. """ diff --git a/layrz_sdk/entities/charts/timeline.py b/layrz_sdk/entities/charts/timeline.py index 67cbb86..581bc62 100644 --- a/layrz_sdk/entities/charts/timeline.py +++ b/layrz_sdk/entities/charts/timeline.py @@ -1,6 +1,7 @@ -""" Timeline chart entities """ +"""Timeline chart entities""" + from datetime import datetime -from typing import Any, List, Self +from typing import Any, List from .alignment import ChartAlignment from .exceptions import ChartException @@ -11,7 +12,7 @@ class TimelineSerieItem: Chart Data Serie Item for Timeline Charts """ - def __init__(self: Self, name: str, start_at: datetime, end_at: datetime, color: str) -> None: + def __init__(self, name: str, start_at: datetime, end_at: datetime, color: str) -> None: """ Constructor ---- @@ -43,7 +44,7 @@ class TimelineSerie: Chart Data Serie for Timeline charts """ - def __init__(self: Self, data: List[TimelineSerieItem], label: str) -> None: + def __init__(self, data: List[TimelineSerieItem], label: str) -> None: """ Constructor ---- @@ -67,7 +68,7 @@ class TimelineChart: """ def __init__( - self: Self, + self, series: List[TimelineSerie], title: str = 'Chart', align: ChartAlignment = ChartAlignment.CENTER, @@ -94,14 +95,14 @@ def __init__( raise ChartException('align must be an instance of ChartAlignment') self.align = align - def render(self: Self) -> Any: + def render(self) -> Any: """ Render chart to a Javascript Library. Currently only available for ApexCharts. """ return {'library': 'APEXCHARTS', 'configuration': self._render_apexcharts()} - def _render_apexcharts(self: Self) -> Any: + def _render_apexcharts(self) -> Any: """ Converts the configuration of the chart to Javascript library ApexCharts. """ @@ -112,11 +113,13 @@ def _render_apexcharts(self: Self) -> Any: data = [] for item in serie.data: - data.append({ - 'x': item.name, - 'y': [item.start_at.timestamp() * 1000, item.end_at.timestamp() * 1000], - 'fillColor': item.color - }) + data.append( + { + 'x': item.name, + 'y': [item.start_at.timestamp() * 1000, item.end_at.timestamp() * 1000], + 'fillColor': item.color, + } + ) series.append({'name': serie.label, 'data': data}) @@ -125,35 +128,21 @@ def _render_apexcharts(self: Self) -> Any: 'title': { 'text': self.title, 'align': self.align.value, - 'style': { - 'fontFamily': 'Fira Sans Condensed', - 'fontSize': '20px', - 'fontWeight': 'normal' - } + 'style': {'fontFamily': 'Fira Sans Condensed', 'fontSize': '20px', 'fontWeight': 'normal'}, }, 'chart': { 'type': 'rangeBar', - 'animations': { - 'enabled': False - }, - 'toolbar': { - 'show': False - }, - 'zoom': { - 'enabled': False - } - }, - 'xaxis': { - 'type': 'datetime' + 'animations': {'enabled': False}, + 'toolbar': {'show': False}, + 'zoom': {'enabled': False}, }, + 'xaxis': {'type': 'datetime'}, 'plotOptions': { 'bar': { 'horizontal': True, } }, - 'dataLabels': { - 'enabled': True - } + 'dataLabels': {'enabled': True}, } return config diff --git a/layrz_sdk/entities/checkpoints/checkpoint.py b/layrz_sdk/entities/checkpoints/checkpoint.py index db95c28..c5e166a 100644 --- a/layrz_sdk/entities/checkpoints/checkpoint.py +++ b/layrz_sdk/entities/checkpoints/checkpoint.py @@ -1,6 +1,7 @@ -""" Checkpoints entitites """ +"""Checkpoints entitites""" + from datetime import datetime -from typing import List, Self +from typing import List from .waypoint import Waypoint @@ -18,14 +19,14 @@ class Checkpoint: """ def __init__( - self: Self, + self, pk: int, asset_id: int, waypoints: List[Waypoint], start_at: datetime, end_at: datetime, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.asset_id = asset_id self.waypoints = waypoints @@ -33,15 +34,17 @@ def __init__( self.end_at = end_at @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Checkpoint(pk={self.pk}, asset_id={self.asset_id}, waypoints={self.waypoints}, ' +\ - f'start_at={self.start_at}, end_at={self.end_at})' + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Checkpoint(pk={self.pk}, asset_id={self.asset_id}, waypoints={self.waypoints}, ' + + f'start_at={self.start_at}, end_at={self.end_at})' + ) - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/checkpoints/geofence.py b/layrz_sdk/entities/checkpoints/geofence.py index e8cf546..447f8e4 100644 --- a/layrz_sdk/entities/checkpoints/geofence.py +++ b/layrz_sdk/entities/checkpoints/geofence.py @@ -1,5 +1,4 @@ -""" Geofence entity """ -from typing import Self +"""Geofence entity""" class Geofence: @@ -12,21 +11,21 @@ class Geofence: - color : Geofence color in Hex format """ - def __init__(self: Self, pk: int, name: str, color: str) -> None: - """ Constructor """ + def __init__(self, pk: int, name: str, color: str) -> None: + """Constructor""" self.pk = pk self.name = name self.color = color @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'Geofence(pk={self.pk}, name={self.name}, color={self.color})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/checkpoints/waypoint.py b/layrz_sdk/entities/checkpoints/waypoint.py index 2f7284e..766a09f 100644 --- a/layrz_sdk/entities/checkpoints/waypoint.py +++ b/layrz_sdk/entities/checkpoints/waypoint.py @@ -1,6 +1,6 @@ -""" Waypoint entity """ +"""Waypoint entity""" + from datetime import datetime -from typing import Self from .geofence import Geofence @@ -19,7 +19,7 @@ class Waypoint: """ def __init__( - self: Self, + self, pk: int, geofence: Geofence, start_at: datetime, @@ -27,7 +27,7 @@ def __init__( sequence_real: int, sequence_ideal: int, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.geofence = geofence self.start_at = start_at @@ -36,15 +36,17 @@ def __init__( self.sequence_ideal = sequence_ideal @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Waypoint(pk={self.pk}, geofence={self.geofence}, start_at={self.start_at}, ' +\ - f'end_at={self.end_at}, sequence_real={self.sequence_real}, sequence_ideal={self.sequence_ideal})' + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Waypoint(pk={self.pk}, geofence={self.geofence}, start_at={self.start_at}, ' + + f'end_at={self.end_at}, sequence_real={self.sequence_real}, sequence_ideal={self.sequence_ideal})' + ) - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/events/event.py b/layrz_sdk/entities/events/event.py index 5e26ff0..1a8cb1c 100644 --- a/layrz_sdk/entities/events/event.py +++ b/layrz_sdk/entities/events/event.py @@ -1,6 +1,6 @@ -""" Event entity """ +"""Event entity""" + from datetime import datetime -from typing import Self from layrz_sdk.entities.cases.trigger import Trigger from layrz_sdk.entities.telemetry.message import Message @@ -20,14 +20,14 @@ class Event: """ def __init__( - self: Self, + self, pk: int, trigger: Trigger, asset_id: int, message: Message, activated_at: datetime, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.trigger = trigger self.asset_id = asset_id @@ -35,15 +35,17 @@ def __init__( self.activated_at = activated_at @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Event(pk={self.pk}, trigger={self.trigger}, asset_id={self.asset_id}, ' +\ - f'message={self.message}, activated_at={self.activated_at})' - - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Event(pk={self.pk}, trigger={self.trigger}, asset_id={self.asset_id}, ' + + f'message={self.message}, activated_at={self.activated_at})' + ) + + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/formatting/text_align.py b/layrz_sdk/entities/formatting/text_align.py index b839f64..8d26a9e 100644 --- a/layrz_sdk/entities/formatting/text_align.py +++ b/layrz_sdk/entities/formatting/text_align.py @@ -1,24 +1,25 @@ -""" Text alignment """ +"""Text alignment""" + from enum import Enum -from typing import Self class TextAlignment(Enum): - """ Text alignment enum definition """ + """Text alignment enum definition""" + CENTER = 'center' LEFT = 'left' RIGHT = 'right' JUSTIFY = 'justify' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'TextAlignment.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/general/asset.py b/layrz_sdk/entities/general/asset.py index 9485527..0abeb51 100644 --- a/layrz_sdk/entities/general/asset.py +++ b/layrz_sdk/entities/general/asset.py @@ -1,5 +1,6 @@ -""" Asset Entity """ -from typing import List, Self +"""Asset Entity""" + +from typing import List from .asset_operation_mode import AssetOperationMode from .custom_field import CustomField @@ -25,7 +26,7 @@ class Asset: """ def __init__( - self: Self, + self, pk: int, name: str, vin: str, @@ -37,7 +38,7 @@ def __init__( devices: List[Device] = None, children: List = None, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.name = name self.vin = vin @@ -54,16 +55,18 @@ def __init__( self.children = [] @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Asset(pk={self.pk}, name={self.name}, vin={self.vin}, plate={self.plate}, ' +\ - f'asset_type={self.asset_type}, operation_mode={self.operation_mode}, ' +\ - f'custom_fields={self.custom_fields}, children={self.children}, sensors={self.sensors})' + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Asset(pk={self.pk}, name={self.name}, vin={self.vin}, plate={self.plate}, ' + + f'asset_type={self.asset_type}, operation_mode={self.operation_mode}, ' + + f'custom_fields={self.custom_fields}, children={self.children}, sensors={self.sensors})' + ) - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/general/asset_operation_mode.py b/layrz_sdk/entities/general/asset_operation_mode.py index 380dc8f..475f369 100644 --- a/layrz_sdk/entities/general/asset_operation_mode.py +++ b/layrz_sdk/entities/general/asset_operation_mode.py @@ -1,6 +1,6 @@ -""" Asset Operation Mode """ +"""Asset Operation Mode""" + from enum import Enum -from typing import Self class AssetOperationMode(Enum): @@ -8,6 +8,7 @@ class AssetOperationMode(Enum): Asset Operation mode definition It's an enum of the operation mode of the asset. """ + SINGLE = 'SINGLE' MULTIPLE = 'MULTIPLE' ASSETMULTIPLE = 'ASSETMULTIPLE' @@ -16,14 +17,14 @@ class AssetOperationMode(Enum): ZONE = 'ZONE' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return self.value - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/general/custom_field.py b/layrz_sdk/entities/general/custom_field.py index 885d47b..ba00cc9 100644 --- a/layrz_sdk/entities/general/custom_field.py +++ b/layrz_sdk/entities/general/custom_field.py @@ -1,5 +1,4 @@ -""" Custom Field entitiy """ -from typing import Self +"""Custom Field entitiy""" class CustomField: @@ -11,20 +10,20 @@ class CustomField: - value : Value of the custom field """ - def __init__(self: Self, name: str, value: str) -> None: - """ Constructor """ + def __init__(self, name: str, value: str) -> None: + """Constructor""" self.name = name self.value = value @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'CustomField(name={self.name}, value={self.value})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/general/device.py b/layrz_sdk/entities/general/device.py index 1b58046..f445da7 100644 --- a/layrz_sdk/entities/general/device.py +++ b/layrz_sdk/entities/general/device.py @@ -1,5 +1,4 @@ -""" Device entitiy """ -from typing import Self +"""Device entitiy""" class Device: @@ -15,14 +14,14 @@ class Device: """ def __init__( - self: Self, + self, pk: int, name: str, ident: str, protocol: str, is_primary: bool = False, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.name = name self.ident = ident @@ -30,15 +29,17 @@ def __init__( self.is_primary = is_primary @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Device(pk={self.pk}, ident={self.ident}, name={self.name}, protocol={self.protocol}, ' +\ - f'is_primary={self.is_primary})' + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Device(pk={self.pk}, ident={self.ident}, name={self.name}, protocol={self.protocol}, ' + + f'is_primary={self.is_primary})' + ) - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/general/sensor.py b/layrz_sdk/entities/general/sensor.py index b3d11f4..b416891 100644 --- a/layrz_sdk/entities/general/sensor.py +++ b/layrz_sdk/entities/general/sensor.py @@ -1,5 +1,4 @@ -""" Sensor entity """ -from typing import Self +"""Sensor entity""" class Sensor: @@ -12,21 +11,21 @@ class Sensor: slug : Slug of the sensor """ - def __init__(self: Self, pk: int, name: str, slug: str) -> None: - """ Constructor """ + def __init__(self, pk: int, name: str, slug: str) -> None: + """Constructor""" self.pk = pk self.name = name self.slug = slug @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'Sensor(pk={self.pk}, name={self.name}, slug={self.slug})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/general/user.py b/layrz_sdk/entities/general/user.py index 28dd0c2..89bd467 100644 --- a/layrz_sdk/entities/general/user.py +++ b/layrz_sdk/entities/general/user.py @@ -1,5 +1,4 @@ -""" User entity """ -from typing import Self +"""User entity""" class User: @@ -11,20 +10,20 @@ class User: name : User name """ - def __init__(self: Self, pk: int, name: str) -> None: - """ Constructor """ + def __init__(self, pk: int, name: str) -> None: + """Constructor""" self.pk = pk self.name = name @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'User(pk={self.pk}, name={self.name})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/repcom/transaction.py b/layrz_sdk/entities/repcom/transaction.py index 3ddb49d..bdb474f 100644 --- a/layrz_sdk/entities/repcom/transaction.py +++ b/layrz_sdk/entities/repcom/transaction.py @@ -1,6 +1,6 @@ -""" Transaction entity """ +"""Transaction entity""" + from datetime import datetime, timedelta -from typing import Self from layrz_sdk.entities.general.asset import Asset @@ -25,7 +25,7 @@ class Transaction: """ def __init__( - self: Self, + self, pk: int, asset: Asset, amount: float, @@ -39,7 +39,7 @@ def __init__( received_at: datetime, is_wildcard: bool, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.asset = asset self.amount = amount diff --git a/layrz_sdk/entities/reports/col.py b/layrz_sdk/entities/reports/col.py index f9da55b..c3c039c 100644 --- a/layrz_sdk/entities/reports/col.py +++ b/layrz_sdk/entities/reports/col.py @@ -1,7 +1,8 @@ -""" Report col """ +"""Report col""" + import warnings from enum import Enum -from typing import Any, Self +from typing import Any from ..formatting.text_align import TextAlignment @@ -10,6 +11,7 @@ class ReportDataType(Enum): """ Report date type """ + STR = 'str' INT = 'int' FLOAT = 'float' @@ -18,16 +20,16 @@ class ReportDataType(Enum): CURRENCY = 'currency' @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ + def _readable(self) -> str | None | bool: + """Readable""" return f'ReportDataType.{self.value}' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable @@ -48,7 +50,7 @@ class ReportCol: """ def __init__( - self: Self, + self, content: Any, color: str = '#ffffff', text_color: str = None, @@ -71,14 +73,14 @@ def __init__( self.bold = bold @property - def _readable(self: Self) -> str | None | bool: - """ Readable property """ + def _readable(self) -> str | None | bool: + """Readable property""" return f'ReportCol(content={self.content})' - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/reports/format.py b/layrz_sdk/entities/reports/format.py index 625b81f..13b5469 100644 --- a/layrz_sdk/entities/reports/format.py +++ b/layrz_sdk/entities/reports/format.py @@ -1,7 +1,6 @@ """Report formats""" from enum import Enum -from typing import Self class ReportFormat(Enum): @@ -14,14 +13,14 @@ class ReportFormat(Enum): PDF = 'PDF' @property - def _readable(self: Self) -> str: + def _readable(self) -> str: """Readable""" return f'ReportFormat.{self.value}' - def __str__(self: Self) -> str: + def __str__(self) -> str: """Readable property""" return self._readable - def __repr__(self: Self) -> str: + def __repr__(self) -> str: """Readable property""" return self._readable diff --git a/layrz_sdk/entities/reports/header.py b/layrz_sdk/entities/reports/header.py index 494c18f..a4fa39e 100644 --- a/layrz_sdk/entities/reports/header.py +++ b/layrz_sdk/entities/reports/header.py @@ -1,7 +1,6 @@ """Report header""" import warnings -from typing import Self from ..formatting.text_align import TextAlignment @@ -23,7 +22,7 @@ class ReportHeader: """ def __init__( - self: Self, + self, content: str, width: int = None, color: str = '#ffffff', @@ -45,14 +44,14 @@ def __init__( self.bold = bold @property - def _readable(self: Self) -> str | None | bool: + def _readable(self) -> str | None | bool: """Readable property""" return f'ReportHeader(content={self.content})' - def __str__(self: Self) -> str | None | bool: + def __str__(self) -> str | None | bool: """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: + def __repr__(self) -> str | None | bool: """Readable property""" return self._readable diff --git a/layrz_sdk/entities/reports/page.py b/layrz_sdk/entities/reports/page.py index 9806850..32dc56f 100644 --- a/layrz_sdk/entities/reports/page.py +++ b/layrz_sdk/entities/reports/page.py @@ -1,5 +1,6 @@ -""" Report page """ -from typing import List, Self +"""Report page""" + +from typing import List from .header import ReportHeader from .row import ReportRow @@ -16,7 +17,7 @@ class ReportPage: """ def __init__( - self: Self, + self, name: str, headers: List[ReportHeader], rows: List[ReportRow], @@ -28,16 +29,16 @@ def __init__( self.freeze_header = freeze_header @property - def _readable(self: Self) -> str | None | bool: - """ Readable property """ + def _readable(self) -> str | None | bool: + """Readable property""" return f'ReportPage(name={self.name}, headers={self.headers}, rows={self.rows})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable @@ -54,8 +55,8 @@ class CustomReportPage: return anything. """ - def __init__(self: Self, name: str, builder: callable) -> None: - """ Constructor """ + def __init__(self, name: str, builder: callable) -> None: + """Constructor""" self.name = name if not callable(builder): diff --git a/layrz_sdk/entities/reports/report.py b/layrz_sdk/entities/reports/report.py index 7348ef1..3444123 100644 --- a/layrz_sdk/entities/reports/report.py +++ b/layrz_sdk/entities/reports/report.py @@ -4,7 +4,7 @@ import os import time import warnings -from typing import Any, Dict, List, Self +from typing import Any, Dict, List import xlsxwriter @@ -28,7 +28,7 @@ class Report: """ def __init__( - self: Self, + self, name: str, pages: List[ReportPage | CustomReportPage], export_format: ReportFormat = None, @@ -46,25 +46,25 @@ def __init__( self.export_format = export_format @property - def filename(self: Self) -> str | None | bool: + def filename(self) -> str | None | bool: """Report filename""" return f'{self.name}_{int(time.time() * 1000)}.xlsx' @property - def _readable(self: Self) -> str | None | bool: + def _readable(self) -> str | None | bool: """Readable property""" return f'Report(name={self.name}, pages={len(self.pages)})' - def __repr__(self: Self) -> str | None | bool: + def __repr__(self) -> str | None | bool: """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: + def __str__(self) -> str | None | bool: """Readable property""" return self._readable def export( - self: Self, + self, path: str, export_format: ReportFormat = None, password: str = None, @@ -103,11 +103,11 @@ def export( else: raise AttributeError(f'Unsupported export format: {self.export_format}') - def export_as_json(self: Self) -> Dict[str, Any]: + def export_as_json(self) -> Dict[str, Any]: """Returns the report as a JSON dict""" return self._export_json() - def _export_json(self: Self) -> Dict[str, Any]: + def _export_json(self) -> Dict[str, Any]: """Returns a JSON dict of the report""" json_pages = [] for page in self.pages: @@ -152,7 +152,7 @@ def _export_json(self: Self) -> Dict[str, Any]: } def _export_xlsx( - self: Self, + self, path: str, password: str = None, msoffice_crypt_path: str = None, @@ -268,19 +268,19 @@ class ReportConfiguration: - pages_count : Number of pages in the report """ - def __init__(self: Self, title: str, pages_count: int) -> None: + def __init__(self, title: str, pages_count: int) -> None: self.title = title self.pages_count = pages_count @property - def _readable(self: Self) -> str | None | bool: + def _readable(self) -> str | None | bool: """Readable property""" return f'ReportConfiguration(title={self.title}, pages_count={self.pages_count})' - def __repr__(self: Self) -> str | None | bool: + def __repr__(self) -> str | None | bool: """Readable property""" return self._readable - def __str__(self: Self) -> str | None | bool: + def __str__(self) -> str | None | bool: """Readable property""" return self._readable diff --git a/layrz_sdk/entities/reports/row.py b/layrz_sdk/entities/reports/row.py index f125174..c16e604 100644 --- a/layrz_sdk/entities/reports/row.py +++ b/layrz_sdk/entities/reports/row.py @@ -1,6 +1,6 @@ -""" Report row """ +"""Report row""" -from typing import List, Self +from typing import List from .col import ReportCol @@ -17,12 +17,12 @@ class ReportRow: """ def __init__( - self: Self, + self, content: List[ReportCol], height: float = None, compact: bool = False, ) -> None: - """ Constructor """ + """Constructor""" self.content = content self.compact = compact @@ -30,14 +30,14 @@ def __init__( raise DeprecationWarning('height is deprecated.') @property - def _readable(self: Self) -> str | None | bool: - """ Readable property """ + def _readable(self) -> str | None | bool: + """Readable property""" return f'ReportRow(content={self.content})' - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/entities/telemetry/message.py b/layrz_sdk/entities/telemetry/message.py index ec16f8e..fb159c2 100644 --- a/layrz_sdk/entities/telemetry/message.py +++ b/layrz_sdk/entities/telemetry/message.py @@ -1,6 +1,7 @@ -""" Message entity """ +"""Message entity""" + from datetime import datetime, timezone -from typing import Any, Self +from typing import Any from .position import Position @@ -19,7 +20,7 @@ class Message: """ def __init__( - self: Self, + self, pk: int, asset_id: int, position: Position = None, @@ -27,7 +28,7 @@ def __init__( sensors: Any = None, received_at: datetime = None, ) -> None: - """ Constructor """ + """Constructor""" self.pk = pk self.asset_id = asset_id self.position = position or Position() diff --git a/layrz_sdk/entities/telemetry/position.py b/layrz_sdk/entities/telemetry/position.py index 88e0f37..6d1c2b7 100644 --- a/layrz_sdk/entities/telemetry/position.py +++ b/layrz_sdk/entities/telemetry/position.py @@ -1,5 +1,4 @@ -""" Position entity """ -from typing import Self +"""Position entity""" class Position: @@ -17,7 +16,7 @@ class Position: """ def __init__( - self: Self, + self, latitude: float = None, longitude: float = None, altitude: float = None, @@ -26,7 +25,7 @@ def __init__( direction: float = None, satellites: int = None, ) -> None: - """ Constructor """ + """Constructor""" self.latitude = latitude self.longitude = longitude self.altitude = altitude @@ -36,15 +35,17 @@ def __init__( self.satellites = satellites @property - def _readable(self: Self) -> str | None | bool: - """ Readable """ - return f'Position(latitude={self.latitude}, longitude={self.longitude}, altitude={self.altitude}, ' +\ - f'speed={self.speed}, direction={self.direction}, hdop={self.hdop}, satellites={self.satellites})' + def _readable(self) -> str | None | bool: + """Readable""" + return ( + f'Position(latitude={self.latitude}, longitude={self.longitude}, altitude={self.altitude}, ' + + f'speed={self.speed}, direction={self.direction}, hdop={self.hdop}, satellites={self.satellites})' + ) - def __str__(self: Self) -> str | None | bool: - """ Readable property """ + def __str__(self) -> str | None | bool: + """Readable property""" return self._readable - def __repr__(self: Self) -> str | None | bool: - """ Readable property """ + def __repr__(self) -> str | None | bool: + """Readable property""" return self._readable diff --git a/layrz_sdk/lcl/core.py b/layrz_sdk/lcl/core.py index 5814dbb..ab6054e 100644 --- a/layrz_sdk/lcl/core.py +++ b/layrz_sdk/lcl/core.py @@ -1,7 +1,7 @@ """Layrz Compute Language SDK""" # ruff: noqa: ANN401 -from typing import Any, Dict, List, Self +from typing import Any, Dict, List PATTERN_INVALID = 'Pattern should be string, received {received}' INVALID_NUMBER_OF_PARAMS = 'Invalid number of arguments - Expected {expected} - Given {received}' @@ -14,7 +14,7 @@ class LclCore: """Layrz Compute Language SDK""" def __init__( # pylint: disable=dangerous-default-value - self: Self, + self, script: str = '', sensors: Dict = None, previous_sensors: Dict = None, @@ -41,7 +41,7 @@ def __init__( # pylint: disable=dangerous-default-value self._script = script def perform( # pylint: disable=dangerous-default-value, invalid-name - self: Self, + self, additional_globals: Dict = None, additional_locals: Dict = None, ) -> str: @@ -130,7 +130,7 @@ def perform( # pylint: disable=dangerous-default-value, invalid-name return json.dumps(INVALID_ARGUMENTS.format(e=err)) - def GET_PARAM(self: Self, *args: List[Any]) -> Any: + def GET_PARAM(self, *args: List[Any]) -> Any: """GET_PARAM Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -142,13 +142,13 @@ def GET_PARAM(self: Self, *args: List[Any]) -> Any: return self._payload.get(args[0], args[1]) return self._payload.get(args[0], None) - def GET_DISTANCE_TRAVELED(self: Self, *args: List[Any]) -> str | float: + def GET_DISTANCE_TRAVELED(self, *args: List[Any]) -> str | float: """GET_DISTANCE_TRAVELED Function""" if len(args) > 0: return INVALID_NUMBER_OF_PARAMS.format(expected=0, received=len(args)) return self._asset_constants.get('distanceTraveled', 0) - def GET_PREVIOUS_SENSOR(self: Self, *args: List[Any]) -> Any: + def GET_PREVIOUS_SENSOR(self, *args: List[Any]) -> Any: """GET_PREVIOUS_SENSOR Function""" if len(args) < 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -163,7 +163,7 @@ def GET_PREVIOUS_SENSOR(self: Self, *args: List[Any]) -> Any: return self._previous_sensors.get(args[0], args[1]) return self._previous_sensors.get(args[0], None) - def GET_SENSOR(self: Self, *args: List[Any]) -> Any: + def GET_SENSOR(self, *args: List[Any]) -> Any: """GET_SENSOR Function""" if len(args) < 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -178,19 +178,19 @@ def GET_SENSOR(self: Self, *args: List[Any]) -> Any: return self._sensors.get(args[0], args[1]) return self._sensors.get(args[0], None) - def CONSTANT(self: Self, *args: List[Any]) -> Any: + def CONSTANT(self, *args: List[Any]) -> Any: """CONSTANT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) return args[0] - def GET_CUSTOM_FIELD(self: Self, *args: List[Any]) -> str: + def GET_CUSTOM_FIELD(self, *args: List[Any]) -> str: """GET_CUSTOM_FIELD Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) return self._custom_fields.get(args[0], '') - def COMPARE(self: Self, *args: List[Any]) -> str | None | bool: + def COMPARE(self, *args: List[Any]) -> str | None | bool: """COMPARE Function""" if len(args) != 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -202,7 +202,7 @@ def COMPARE(self: Self, *args: List[Any]) -> str | None | bool: return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] == args[1] - def OR_OPERATOR(self: Self, *args: List[Any]) -> bool: + def OR_OPERATOR(self, *args: List[Any]) -> bool: """OR_OPERATOR Function""" result = False @@ -214,7 +214,7 @@ def OR_OPERATOR(self: Self, *args: List[Any]) -> bool: return result - def AND_OPERATOR(self: Self, *args: List[Any]) -> bool: + def AND_OPERATOR(self, *args: List[Any]) -> bool: """AND_OPERATOR Function""" result = False is_first = True @@ -231,7 +231,7 @@ def AND_OPERATOR(self: Self, *args: List[Any]) -> bool: return result - def SUM(self: Self, *args: List[Any]) -> float: + def SUM(self, *args: List[Any]) -> float: """SUM Function""" result = 0 @@ -246,7 +246,7 @@ def SUM(self: Self, *args: List[Any]) -> float: return result - def SUBSTRACT(self: Self, *args: List[Any]) -> float: + def SUBSTRACT(self, *args: List[Any]) -> float: """SUBSTRACT Function""" result = 0 is_first = True @@ -266,7 +266,7 @@ def SUBSTRACT(self: Self, *args: List[Any]) -> float: return result - def MULTIPLY(self: Self, *args: List[Any]) -> float: + def MULTIPLY(self, *args: List[Any]) -> float: """MULTIPLY Function""" result = 0 is_first = True @@ -286,7 +286,7 @@ def MULTIPLY(self: Self, *args: List[Any]) -> float: return result - def DIVIDE(self: Self, *args: List[Any]) -> float: + def DIVIDE(self, *args: List[Any]) -> float: """DIVIDE Function""" result = 0 is_first = True @@ -306,7 +306,7 @@ def DIVIDE(self: Self, *args: List[Any]) -> float: return result - def TO_BOOL(self: Self, *args: List[Any]) -> str | None | bool: + def TO_BOOL(self, *args: List[Any]) -> str | None | bool: """TO_BOOL Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -316,7 +316,7 @@ def TO_BOOL(self: Self, *args: List[Any]) -> str | None | bool: return bool(args[0]) - def TO_STR(self: Self, *args: List[Any]) -> str | None: + def TO_STR(self, *args: List[Any]) -> str | None: """TO_STR Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -326,7 +326,7 @@ def TO_STR(self: Self, *args: List[Any]) -> str | None: return str(args[0]) - def TO_INT(self: Self, *args: List[Any]) -> str | None | int: + def TO_INT(self, *args: List[Any]) -> str | None | int: """TO_INT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -336,7 +336,7 @@ def TO_INT(self: Self, *args: List[Any]) -> str | None | int: return int(args[0]) - def CEIL(self: Self, *args: List[Any]) -> str | None | int: + def CEIL(self, *args: List[Any]) -> str | None | int: """CEIL Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -351,7 +351,7 @@ def CEIL(self: Self, *args: List[Any]) -> str | None | int: return math.ceil(args[0]) - def FLOOR(self: Self, *args: List[Any]) -> str | None | int: + def FLOOR(self, *args: List[Any]) -> str | None | int: """FLOOR Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -366,7 +366,7 @@ def FLOOR(self: Self, *args: List[Any]) -> str | None | int: return math.floor(args[0]) - def ROUND(self: Self, *args: List[Any]) -> str | None | int: + def ROUND(self, *args: List[Any]) -> str | None | int: """ROUND Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -379,7 +379,7 @@ def ROUND(self: Self, *args: List[Any]) -> str | None | int: return round(args[0]) - def SQRT(self: Self, *args: List[Any]) -> str | None | float: + def SQRT(self, *args: List[Any]) -> str | None | float: """SQRT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -391,7 +391,7 @@ def SQRT(self: Self, *args: List[Any]) -> str | None | float: return math.sqrt(args[0]) - def CONCAT(self: Self, *args: List[Any]) -> str | None: + def CONCAT(self, *args: List[Any]) -> str | None: """CONCAT Function""" for val in args: if val is None: @@ -399,7 +399,7 @@ def CONCAT(self: Self, *args: List[Any]) -> str | None: return ''.join([str(val) for val in args]) - def RANDOM(self: Self, *args: List[Any]) -> float | str: + def RANDOM(self, *args: List[Any]) -> float | str: """RANDOM Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -413,7 +413,7 @@ def RANDOM(self: Self, *args: List[Any]) -> float | str: return random.random() * (float(args[1]) - float(args[0])) + float(args[0]) - def RANDOM_INT(self: Self, *args: List[Any]) -> int | str: + def RANDOM_INT(self, *args: List[Any]) -> int | str: """RANDOM_INT Function""" if len(args) != 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -425,7 +425,7 @@ def RANDOM_INT(self: Self, *args: List[Any]) -> int | str: return random.randint(int(args[0]), int(args[1])) - def GREATER_THAN_OR_EQUALS_TO(self: Self, *args: List[Any]) -> str | None | bool: + def GREATER_THAN_OR_EQUALS_TO(self, *args: List[Any]) -> str | None | bool: """GREATER_THAN_OR_EQUALS_TO Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -439,7 +439,7 @@ def GREATER_THAN_OR_EQUALS_TO(self: Self, *args: List[Any]) -> str | None | bool return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] >= args[1] - def GREATER_THAN(self: Self, *args: List[Any]) -> str | None | bool: + def GREATER_THAN(self, *args: List[Any]) -> str | None | bool: """GREATER_THAN Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -453,7 +453,7 @@ def GREATER_THAN(self: Self, *args: List[Any]) -> str | None | bool: return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] > args[1] - def LESS_THAN_OR_EQUALS_TO(self: Self, *args: List[Any]) -> str | None | bool: + def LESS_THAN_OR_EQUALS_TO(self, *args: List[Any]) -> str | None | bool: """LESS_THAN_OR_EQUALS_TO Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -467,7 +467,7 @@ def LESS_THAN_OR_EQUALS_TO(self: Self, *args: List[Any]) -> str | None | bool: return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] <= args[1] - def LESS_THAN(self: Self, *args: List[Any]) -> str | None | bool: + def LESS_THAN(self, *args: List[Any]) -> str | None | bool: """LESS_THAN Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -481,7 +481,7 @@ def LESS_THAN(self: Self, *args: List[Any]) -> str | None | bool: return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] < args[1] - def DIFFERENT(self: Self, *args: List[Any]) -> str | None | bool: + def DIFFERENT(self, *args: List[Any]) -> str | None | bool: """DIFFERENT Function""" if len(args) > 2: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -495,7 +495,7 @@ def DIFFERENT(self: Self, *args: List[Any]) -> str | None | bool: return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] != args[1] - def HEX_TO_STR(self: Self, *args: List[Any]) -> str | None: + def HEX_TO_STR(self, *args: List[Any]) -> str | None: """HEX_TO_STR Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -513,7 +513,7 @@ def HEX_TO_STR(self: Self, *args: List[Any]) -> str | None: except Exception: # pylint: disable=broad-except return 'Invalid hex string' - def STR_TO_HEX(self: Self, *args: List[Any]) -> str | None: + def STR_TO_HEX(self, *args: List[Any]) -> str | None: """STR_TO_HEX Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -523,7 +523,7 @@ def STR_TO_HEX(self: Self, *args: List[Any]) -> str | None: return str(args[0]).encode('ASCII').hex() - def HEX_TO_INT(self: Self, *args: List[Any]) -> str | None | int: + def HEX_TO_INT(self, *args: List[Any]) -> str | None | int: """HEX_TO_INT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -536,7 +536,7 @@ def HEX_TO_INT(self: Self, *args: List[Any]) -> str | None | int: except Exception: # pylint: disable=broad-except return 'Invalid hex string' - def INT_TO_HEX(self: Self, *args: List[Any]) -> str | None: + def INT_TO_HEX(self, *args: List[Any]) -> str | None: """INT_TO_HEX Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -549,7 +549,7 @@ def INT_TO_HEX(self: Self, *args: List[Any]) -> str | None: except Exception: # pylint: disable=broad-except return 'Invalid int value' - def TO_FLOAT(self: Self, *args: List[Any]) -> str | None | float: + def TO_FLOAT(self, *args: List[Any]) -> str | None | float: """TO_FLOAT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -562,7 +562,7 @@ def TO_FLOAT(self: Self, *args: List[Any]) -> str | None | float: except Exception: # pylint: disable=broad-except return f'Invalid arguments - must be real number, not {type(args[0]).__name__}' - def IS_PARAMETER_PRESENT(self: Self, *args: List[Any]) -> str | bool: + def IS_PARAMETER_PRESENT(self, *args: List[Any]) -> str | bool: """IS_PARAMETER_PRESENT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -572,7 +572,7 @@ def IS_PARAMETER_PRESENT(self: Self, *args: List[Any]) -> str | bool: return args[0] in self._payload - def IS_SENSOR_PRESENT(self: Self, *args: List[Any]) -> str | bool: + def IS_SENSOR_PRESENT(self, *args: List[Any]) -> str | bool: """IS_SENSOR_PRESENT Function""" if len(args) > 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -582,7 +582,7 @@ def IS_SENSOR_PRESENT(self: Self, *args: List[Any]) -> str | bool: return args[0] in self._sensors - def INSIDE_RANGE(self: Self, *args: List[Any]) -> str | None | bool: + def INSIDE_RANGE(self, *args: List[Any]) -> str | None | bool: """INSIDE_RANGE Function""" if len(args) != 3: return INVALID_NUMBER_OF_PARAMS.format(expected=3, received=len(args)) @@ -599,7 +599,7 @@ def INSIDE_RANGE(self: Self, *args: List[Any]) -> str | None | bool: return args[1] <= args[0] <= args[2] - def OUTSIDE_RANGE(self: Self, *args: List[Any]) -> str | None | bool: + def OUTSIDE_RANGE(self, *args: List[Any]) -> str | None | bool: """OUTSIDE_RANGE Function""" if len(args) != 3: return INVALID_NUMBER_OF_PARAMS.format(expected=3, received=len(args)) @@ -616,14 +616,14 @@ def OUTSIDE_RANGE(self: Self, *args: List[Any]) -> str | None | bool: return not args[1] <= args[0] <= args[2] - def GET_TIME_DIFFERENCE(self: Self, *args: List[Any]) -> str | float: + def GET_TIME_DIFFERENCE(self, *args: List[Any]) -> str | float: """GET_TIME_DIFFERENCE Function""" if len(args) > 0: return INVALID_NUMBER_OF_PARAMS.format(expected=0, received=len(args)) return self._asset_constants.get('timeElapsed', 0) - def IF(self: Self, *args: list[Any]) -> Any: + def IF(self, *args: list[Any]) -> Any: """IF Function""" if len(args) != 3: return INVALID_NUMBER_OF_PARAMS.format(expected=3, received=len(args)) @@ -633,14 +633,14 @@ def IF(self: Self, *args: list[Any]) -> Any: return args[1] if args[0] else args[2] - def NOW(self: Self, *args: List[Any]) -> float: + def NOW(self, *args: List[Any]) -> float: """NOW Function""" import zoneinfo from datetime import datetime return datetime.now(tz=zoneinfo.ZoneInfo('UTC')).timestamp() - def REGEX(self: Self, *args: List[Any]) -> str | None | bool: + def REGEX(self, *args: List[Any]) -> str | None | bool: """REGEX Function""" if len(args) != 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -656,14 +656,14 @@ def REGEX(self: Self, *args: List[Any]) -> str | None | bool: pattern = re.compile(args[1]) return bool(pattern.match(args[0])) - def IS_NONE(self: Self, *args: List[Any]) -> str | bool: + def IS_NONE(self, *args: List[Any]) -> str | bool: """IS_NONE Function""" if len(args) != 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) return args[0] is None - def NOT(self: Self, *args: List[Any]) -> str | bool: + def NOT(self, *args: List[Any]) -> str | bool: """NOT Function""" if len(args) != 1: return INVALID_NUMBER_OF_PARAMS.format(expected=1, received=len(args)) @@ -673,7 +673,7 @@ def NOT(self: Self, *args: List[Any]) -> str | bool: return not args[0] - def CONTAINS(self: Self, *args: List[Any]) -> str | bool: + def CONTAINS(self, *args: List[Any]) -> str | bool: """CONTAINS function""" if len(args) != 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -683,7 +683,7 @@ def CONTAINS(self: Self, *args: List[Any]) -> str | bool: return str(args[0]) in str(args[1]) - def STARTS_WITH(self: Self, *args: List[Any]) -> str | bool: + def STARTS_WITH(self, *args: List[Any]) -> str | bool: """STARTS_WITH function""" if len(args) != 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -693,7 +693,7 @@ def STARTS_WITH(self: Self, *args: List[Any]) -> str | bool: return str(args[1]).startswith(str(args[0])) - def ENDS_WITH(self: Self, *args: List[Any]) -> str | bool: + def ENDS_WITH(self, *args: List[Any]) -> str | bool: """ENDS_WITH function""" if len(args) != 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -703,14 +703,14 @@ def ENDS_WITH(self: Self, *args: List[Any]) -> str | bool: return str(args[1]).endswith(str(args[0])) - def PRIMARY_DEVICE(self: Self, *args: List[Any]) -> str: + def PRIMARY_DEVICE(self, *args: List[Any]) -> str: """PRIMARY_DEVICE function""" if len(args) > 0: return INVALID_NUMBER_OF_PARAMS.format(expected=0, received=len(args)) return self._asset_constants.get('primaryDevice', None) - def SUBSTRING(self: Self, *args: List[Any]) -> str: + def SUBSTRING(self, *args: List[Any]) -> str: """Get a substring from string (args[0])""" if len(args) < 2: return INVALID_NUMBER_OF_PARAMS.format( @@ -746,7 +746,7 @@ def SUBSTRING(self: Self, *args: List[Any]) -> str: return args[0][args[1] : args[2]] return args[0][args[1] :] - def UNIX_TO_STR(self: Self, *args: List[Any]) -> str: + def UNIX_TO_STR(self, *args: List[Any]) -> str: """Convert UNIX timestamp date (args[0]) to format (args[1]) string""" if len(args) < 2: return INVALID_NUMBER_OF_PARAMS.format(expected=2, received=len(args)) @@ -773,7 +773,7 @@ def UNIX_TO_STR(self: Self, *args: List[Any]) -> str: return datetime.fromtimestamp(int(args[0]), tz=zoneinfo.ZoneInfo('UTC')).astimezone(tz).strftime(args[1]) - def VERSION(self: Self, *args: List[Any]) -> str: + def VERSION(self, *args: List[Any]) -> str: """VERSION function""" if len(args) > 0: return INVALID_NUMBER_OF_PARAMS.format(expected=0, received=len(args)) diff --git a/pyproject.toml b/pyproject.toml index a193359..ed5e119 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "layrz-sdk" -version = "3.0.9" +version = "3.0.10" description = "Layrz SDK for Python" authors = [ {name = "Golden M, Inc.", email = "software@goldenm.com"} @@ -55,6 +55,7 @@ ignore = [ "E701", # Multiple statements on one line "TD003", # Missing issue link 'ANN401', # Type Any has no effect + 'ANN101', # Missing type annotation for self ] exclude = [ diff --git a/tests/test_lcl.py b/tests/test_lcl.py index c2b0d9f..2c2d9b5 100644 --- a/tests/test_lcl.py +++ b/tests/test_lcl.py @@ -6,7 +6,7 @@ import unittest import zoneinfo from datetime import datetime -from typing import Any, Self +from typing import Any from layrz_sdk.lcl.core import LclCore @@ -14,7 +14,7 @@ class TestLclFunctions(unittest.TestCase): """Test LCL functions""" - def _process_and_convert(self: Self, lcl: LclCore) -> Any: + def _process_and_convert(self, lcl: LclCore) -> Any: result = lcl.perform() try: result = json.loads(result) @@ -23,7 +23,7 @@ def _process_and_convert(self: Self, lcl: LclCore) -> Any: return result - def test_GET_PARAM(self: Self) -> None: + def test_GET_PARAM(self) -> None: formula = 'GET_PARAM("test.param", None)' lcl = LclCore(script=formula, payload={'test.param': 10}) result = self._process_and_convert(lcl) @@ -33,7 +33,7 @@ def test_GET_PARAM(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_GET_SENSOR(self: Self) -> None: + def test_GET_SENSOR(self) -> None: formula = 'GET_SENSOR("test.sensor", None)' lcl = LclCore(script=formula, sensors={'test.sensor': 10}) result = self._process_and_convert(lcl) @@ -43,7 +43,7 @@ def test_GET_SENSOR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_CONSTANT(self: Self) -> None: + def test_CONSTANT(self) -> None: formula = 'CONSTANT(True)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -61,7 +61,7 @@ def test_CONSTANT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 10.0) - def test_GET_CUSTOM_FIELD(self: Self) -> None: + def test_GET_CUSTOM_FIELD(self) -> None: formula = 'GET_CUSTOM_FIELD("test.custom_field")' lcl = LclCore(script=formula, custom_fields={'test.custom_field': 10}) result = self._process_and_convert(lcl) @@ -71,7 +71,7 @@ def test_GET_CUSTOM_FIELD(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, '') - def test_COMPARE(self: Self) -> None: + def test_COMPARE(self) -> None: formula = 'COMPARE(CONSTANT(10), CONSTANT(10))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -92,7 +92,7 @@ def test_COMPARE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, False) - def test_OR_OPERATOR(self: Self) -> None: + def test_OR_OPERATOR(self) -> None: formula = 'OR_OPERATOR(CONSTANT(True), CONSTANT(False))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -113,7 +113,7 @@ def test_OR_OPERATOR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_AND_OPERATOR(self: Self) -> None: + def test_AND_OPERATOR(self) -> None: formula = 'AND_OPERATOR(CONSTANT(True), CONSTANT(False))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -134,7 +134,7 @@ def test_AND_OPERATOR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_SUM(self: Self) -> None: + def test_SUM(self) -> None: formula = 'SUM(CONSTANT(10), CONSTANT(20))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -145,7 +145,7 @@ def test_SUM(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_SUBSTRACT(self: Self) -> None: + def test_SUBSTRACT(self) -> None: formula = 'SUBSTRACT(CONSTANT(10), CONSTANT(20))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -161,7 +161,7 @@ def test_SUBSTRACT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_MULTIPLY(self: Self) -> None: + def test_MULTIPLY(self) -> None: formula = 'MULTIPLY(CONSTANT(10), CONSTANT(20))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -177,7 +177,7 @@ def test_MULTIPLY(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_DIVIDE(self: Self) -> None: + def test_DIVIDE(self) -> None: formula = 'DIVIDE(CONSTANT(10), CONSTANT(20))' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -193,7 +193,7 @@ def test_DIVIDE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_TO_BOOL(self: Self) -> None: + def test_TO_BOOL(self) -> None: formula = 'TO_BOOL(1)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -219,7 +219,7 @@ def test_TO_BOOL(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, True) # Why? Simple, any filled str is True - def test_TO_STR(self: Self) -> None: + def test_TO_STR(self) -> None: formula = 'TO_STR(1)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -240,7 +240,7 @@ def test_TO_STR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_TO_INT(self: Self) -> None: + def test_TO_INT(self) -> None: formula = 'TO_INT(1.5)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -261,7 +261,7 @@ def test_TO_INT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_CEIL(self: Self) -> None: + def test_CEIL(self) -> None: formula = 'CEIL(1.2)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -287,7 +287,7 @@ def test_CEIL(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_FLOOR(self: Self) -> None: + def test_FLOOR(self) -> None: formula = 'FLOOR(1.2)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -313,7 +313,7 @@ def test_FLOOR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_ROUND(self: Self) -> None: + def test_ROUND(self) -> None: formula = 'ROUND(1.2)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -339,7 +339,7 @@ def test_ROUND(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_SQRT(self: Self) -> None: + def test_SQRT(self) -> None: formula = 'SQRT(4)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -365,7 +365,7 @@ def test_SQRT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_CONCAT(self: Self) -> None: + def test_CONCAT(self) -> None: formula = 'CONCAT("Hello", " ", "World")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -386,13 +386,13 @@ def test_CONCAT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'HelloTrueWorld') - def test_NOW(self: Self) -> None: + def test_NOW(self) -> None: formula = 'NOW()' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) self.assertIsInstance(result, (int, float)) - def test_RANDOM(self: Self) -> None: + def test_RANDOM(self) -> None: formula = 'RANDOM(0, 1)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -400,7 +400,7 @@ def test_RANDOM(self: Self) -> None: self.assertGreaterEqual(result, 0.0) self.assertLessEqual(result, 1.0) - def test_RANDOM_INT(self: Self) -> None: + def test_RANDOM_INT(self) -> None: formula = 'RANDOM_INT(1, 3)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -408,7 +408,7 @@ def test_RANDOM_INT(self: Self) -> None: self.assertGreaterEqual(result, 1) self.assertLessEqual(result, 3) - def test_GREATER_THAN_OR_EQUALS_TO(self: Self) -> None: + def test_GREATER_THAN_OR_EQUALS_TO(self) -> None: formula = 'GREATER_THAN_OR_EQUALS_TO(10, 10)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -434,7 +434,7 @@ def test_GREATER_THAN_OR_EQUALS_TO(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_GREATER_THAN(self: Self) -> None: + def test_GREATER_THAN(self) -> None: formula = 'GREATER_THAN(10, 10)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -460,7 +460,7 @@ def test_GREATER_THAN(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_LESS_THAN_OR_EQUALS_TO(self: Self) -> None: + def test_LESS_THAN_OR_EQUALS_TO(self) -> None: formula = 'LESS_THAN_OR_EQUALS_TO(10, 10)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -486,7 +486,7 @@ def test_LESS_THAN_OR_EQUALS_TO(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_LESS_THAN(self: Self) -> None: + def test_LESS_THAN(self) -> None: formula = 'LESS_THAN(10, 10)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -512,7 +512,7 @@ def test_LESS_THAN(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_DIFFERENT(self: Self) -> None: + def test_DIFFERENT(self) -> None: formula = 'DIFFERENT(10, 10)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -543,7 +543,7 @@ def test_DIFFERENT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'Invalid data types - arg1: str - arg2: int') - def test_HEX_TO_STR(self: Self) -> None: + def test_HEX_TO_STR(self) -> None: formula = 'HEX_TO_STR("48656c6c6f")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -559,13 +559,13 @@ def test_HEX_TO_STR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'Invalid hex string') - def test_STR_TO_HEX(self: Self) -> None: + def test_STR_TO_HEX(self) -> None: formula = 'STR_TO_HEX("Hello")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) self.assertEqual(result, '48656c6c6f') - def test_HEX_TO_INT(self: Self) -> None: + def test_HEX_TO_INT(self) -> None: formula = 'HEX_TO_INT("0xff")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -581,7 +581,7 @@ def test_HEX_TO_INT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'Invalid hex string') - def test_INT_TO_HEX(self: Self) -> None: + def test_INT_TO_HEX(self) -> None: formula = 'INT_TO_HEX(15)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -597,7 +597,7 @@ def test_INT_TO_HEX(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'Invalid int value') - def test_TO_FLOAT(self: Self) -> None: + def test_TO_FLOAT(self) -> None: formula = 'TO_FLOAT(0)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -618,7 +618,7 @@ def test_TO_FLOAT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'Invalid arguments - must be real number, not str') - def test_GET_DISTANCE_TRAVELED(self: Self) -> None: + def test_GET_DISTANCE_TRAVELED(self) -> None: formula = 'GET_DISTANCE_TRAVELED()' lcl = LclCore(script=formula, asset_constants={'distanceTraveled': 10}) result = self._process_and_convert(lcl) @@ -628,7 +628,7 @@ def test_GET_DISTANCE_TRAVELED(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 0.0) - def test_GET_PREVIOUS_SENSOR(self: Self) -> None: + def test_GET_PREVIOUS_SENSOR(self) -> None: formula = 'GET_PREVIOUS_SENSOR("test.sensor")' lcl = LclCore(script=formula, previous_sensors={'test.sensor': 10}) result = self._process_and_convert(lcl) @@ -638,7 +638,7 @@ def test_GET_PREVIOUS_SENSOR(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_IS_PARAMETER_PRESENT(self: Self) -> None: + def test_IS_PARAMETER_PRESENT(self) -> None: formula = 'IS_PARAMETER_PRESENT("test.param")' lcl = LclCore(script=formula, payload={'test.param': 10}) result = self._process_and_convert(lcl) @@ -648,7 +648,7 @@ def test_IS_PARAMETER_PRESENT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, False) - def test_IS_SENSOR_PRESENT(self: Self) -> None: + def test_IS_SENSOR_PRESENT(self) -> None: formula = 'IS_SENSOR_PRESENT("test.sensor")' lcl = LclCore(script=formula, sensors={'test.sensor': 10}) result = self._process_and_convert(lcl) @@ -658,7 +658,7 @@ def test_IS_SENSOR_PRESENT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, False) - def test_INSIDE_RANGE(self: Self) -> None: + def test_INSIDE_RANGE(self) -> None: formula = 'INSIDE_RANGE(10, 20, 30)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -689,7 +689,7 @@ def test_INSIDE_RANGE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_OUTSIDE_RANGE(self: Self) -> None: + def test_OUTSIDE_RANGE(self) -> None: formula = 'OUTSIDE_RANGE(10, 20, 30)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -720,7 +720,7 @@ def test_OUTSIDE_RANGE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_GET_TIME_DIFFERENCE(self: Self) -> None: + def test_GET_TIME_DIFFERENCE(self) -> None: formula = 'GET_TIME_DIFFERENCE()' lcl = LclCore(script=formula, asset_constants={'timeElapsed': 10}) result = self._process_and_convert(lcl) @@ -730,7 +730,7 @@ def test_GET_TIME_DIFFERENCE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 0) - def test_IF(self: Self) -> None: + def test_IF(self) -> None: formula = 'IF(True, 10, 20)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -756,7 +756,7 @@ def test_IF(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_REGEX(self: Self) -> None: + def test_REGEX(self) -> None: formula = 'REGEX("1. Hello world", "^[0-9]+\\.\\s")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -782,7 +782,7 @@ def test_REGEX(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_IS_NONE(self: Self) -> None: + def test_IS_NONE(self) -> None: formula = 'IS_NONE(None)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -793,7 +793,7 @@ def test_IS_NONE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, False) - def test_NOT(self: Self) -> None: + def test_NOT(self) -> None: formula = 'NOT(True)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -814,7 +814,7 @@ def test_NOT(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, False) - def test_CONTAINS(self: Self) -> None: + def test_CONTAINS(self) -> None: formula = 'CONTAINS("Hello", "Hello World")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -835,7 +835,7 @@ def test_CONTAINS(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_STARTS_WITH(self: Self) -> None: + def test_STARTS_WITH(self) -> None: formula = 'STARTS_WITH("Hello", "Hello World")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -856,7 +856,7 @@ def test_STARTS_WITH(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_ENDS_WITH(self: Self) -> None: + def test_ENDS_WITH(self) -> None: formula = 'ENDS_WITH("World", "Hello World")' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -877,7 +877,7 @@ def test_ENDS_WITH(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_PRIMARY_DEVICE(self: Self) -> None: + def test_PRIMARY_DEVICE(self) -> None: formula = 'PRIMARY_DEVICE()' lcl = LclCore(script=formula, asset_constants={'primaryDevice': 'test'}) result = self._process_and_convert(lcl) @@ -888,7 +888,7 @@ def test_PRIMARY_DEVICE(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, None) - def test_SUBSTRING(self: Self) -> None: + def test_SUBSTRING(self) -> None: formula = 'SUBSTRING("Hello World", 0, 5)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) @@ -899,7 +899,7 @@ def test_SUBSTRING(self: Self) -> None: result = self._process_and_convert(lcl) self.assertEqual(result, 'World') - def test_UNIX_TO_STR(self: Self) -> None: + def test_UNIX_TO_STR(self) -> None: formula = 'UNIX_TO_STR(NOW(), "%Y_%m_%d", "UTC")' now = datetime.now(zoneinfo.ZoneInfo('UTC')) lcl = LclCore(script=formula) From 9d4ce479d7671054b2e94caea40356f0645e5292 Mon Sep 17 00:00:00 2001 From: Kenny Mochizuki Date: Thu, 27 Jun 2024 01:16:27 -0600 Subject: [PATCH 2/5] Removed lint.py and downgraded python image version to Python 3.10 --- .github/workflows/checks.yml | 4 ++-- .github/workflows/deploy.yml | 2 +- lint.py | 41 ------------------------------------ 3 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 lint.py diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index d0c76e9..2ee9310 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -13,7 +13,7 @@ jobs: lint: runs-on: ubuntu-latest container: - image: ghcr.io/goldenm-software/python-builder:3.11 + image: ghcr.io/goldenm-software/python-builder:3.10 options: --user root credentials: username: ${{ github.repository_owner }} @@ -35,7 +35,7 @@ jobs: needs: lint runs-on: ubuntu-latest container: - image: ghcr.io/goldenm-software/python-builder:3.11 + image: ghcr.io/goldenm-software/python-builder:3.10 options: --user root credentials: username: ${{ github.repository_owner }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1c1e08d..b6aa514 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/goldenm-software/python-builder:3.11 + image: ghcr.io/goldenm-software/python-builder:3.10 options: --user root credentials: username: ${{ github.repository_owner }} diff --git a/lint.py b/lint.py deleted file mode 100644 index 3312041..0000000 --- a/lint.py +++ /dev/null @@ -1,41 +0,0 @@ -""" Lint files """ -import argparse -import os - -from pylint.lint import Run - -parser = argparse.ArgumentParser(description='Lint code') -parser.add_argument('--module', type=str, help='Module to lint') -args = parser.parse_args() - -IGNORE_FOLDERS = ( - '.venv', - '.git', - '__pycache__', - 'test.py', -) - -IGNORE_EXTENSIONS = ('.pyc', ) - -IGNORE_FILES = ('lint.py', ) - -watch_files = [] -for root, dirs, files in os.walk('.'): - dirs[:] = [d for d in dirs if d not in IGNORE_FOLDERS] - for file in files: - if file.endswith(IGNORE_EXTENSIONS) or file in IGNORE_FILES: - continue - if file.endswith('.py'): - watch_files.append(os.path.join(root, file)) - -if args.module: - watch_files = [f for f in watch_files if args.module in f] - -#print(f'Linting {len(watch_files)} files') - -Run([ - '--rcfile=pyproject.toml', - '--persistent=n', - '--jobs=0', - *watch_files, -]) From c85544035ce19055e0ab82ef07f2ca13d704198c Mon Sep 17 00:00:00 2001 From: Kenny Mochizuki Date: Thu, 27 Jun 2024 01:17:07 -0600 Subject: [PATCH 3/5] Removed pylint disable messages --- layrz_sdk/lcl/core.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/layrz_sdk/lcl/core.py b/layrz_sdk/lcl/core.py index ab6054e..76c14fe 100644 --- a/layrz_sdk/lcl/core.py +++ b/layrz_sdk/lcl/core.py @@ -13,7 +13,7 @@ class LclCore: """Layrz Compute Language SDK""" - def __init__( # pylint: disable=dangerous-default-value + def __init__( self, script: str = '', sensors: Dict = None, @@ -40,7 +40,7 @@ def __init__( # pylint: disable=dangerous-default-value self._custom_fields = custom_fields self._script = script - def perform( # pylint: disable=dangerous-default-value, invalid-name + def perform( self, additional_globals: Dict = None, additional_locals: Dict = None, @@ -122,10 +122,10 @@ def perform( # pylint: disable=dangerous-default-value, invalid-name import json - result = json.dumps(eval(self._script, global_functions, local_variables)) # pylint: disable=eval-used + result = json.dumps(eval(self._script, global_functions, local_variables)) return result - except Exception as err: # pylint: disable=broad-except + except Exception as err: import json return json.dumps(INVALID_ARGUMENTS.format(e=err)) @@ -241,7 +241,7 @@ def SUM(self, *args: List[Any]) -> float: try: result += float(num) - except Exception: # pylint: disable=broad-except + except Exception: pass return result @@ -261,7 +261,7 @@ def SUBSTRACT(self, *args: List[Any]) -> float: is_first = False else: result -= float(num) - except Exception: # pylint: disable=broad-except + except Exception: pass return result @@ -281,7 +281,7 @@ def MULTIPLY(self, *args: List[Any]) -> float: result = float(num) else: result *= float(num) - except Exception: # pylint: disable=broad-except + except Exception: pass return result @@ -301,7 +301,7 @@ def DIVIDE(self, *args: List[Any]) -> float: result = float(num) else: result /= float(num) - except Exception: # pylint: disable=broad-except + except Exception: pass return result @@ -510,7 +510,7 @@ def HEX_TO_STR(self, *args: List[Any]) -> str | None: try: byte_array = bytes.fromhex(hexa) return byte_array.decode('ASCII') - except Exception: # pylint: disable=broad-except + except Exception: return 'Invalid hex string' def STR_TO_HEX(self, *args: List[Any]) -> str | None: @@ -533,7 +533,7 @@ def HEX_TO_INT(self, *args: List[Any]) -> str | None | int: try: return int(int(args[0], 16)) - except Exception: # pylint: disable=broad-except + except Exception: return 'Invalid hex string' def INT_TO_HEX(self, *args: List[Any]) -> str | None: @@ -546,7 +546,7 @@ def INT_TO_HEX(self, *args: List[Any]) -> str | None: try: return hex(int(args[0]))[2:] - except Exception: # pylint: disable=broad-except + except Exception: return 'Invalid int value' def TO_FLOAT(self, *args: List[Any]) -> str | None | float: @@ -559,7 +559,7 @@ def TO_FLOAT(self, *args: List[Any]) -> str | None | float: try: return float(args[0]) - except Exception: # pylint: disable=broad-except + except Exception: return f'Invalid arguments - must be real number, not {type(args[0]).__name__}' def IS_PARAMETER_PRESENT(self, *args: List[Any]) -> str | bool: From 4ec5cca329fea3adb952fb28b96c7069c988dfb7 Mon Sep 17 00:00:00 2001 From: Kenny Mochizuki Date: Tue, 9 Jul 2024 01:12:02 -0600 Subject: [PATCH 4/5] 3.0.11 --- CHANGELOG.md | 4 ++++ layrz_sdk/lcl/core.py | 28 ++++++++++++++++++++++++++++ pyproject.toml | 2 +- tests/test_lcl.py | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba96d37..096f3ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.0.11 + +- Added way to standarize the `int` and `float` arguments to `float`. Allowing comparison between `int` and `float` values in LCL formulas + ## 3.0.10 - Removed Self type annotation from all classes diff --git a/layrz_sdk/lcl/core.py b/layrz_sdk/lcl/core.py index 76c14fe..952edee 100644 --- a/layrz_sdk/lcl/core.py +++ b/layrz_sdk/lcl/core.py @@ -130,6 +130,18 @@ def perform( return json.dumps(INVALID_ARGUMENTS.format(e=err)) + def _standarize_datatypes(self, args: List[Any]) -> List[Any]: + """Standarize data types""" + result_args = [] + + for arg in args: + if isinstance(arg, (float, int)): + result_args.append(float(arg)) + else: + result_args.append(arg) + + return result_args + def GET_PARAM(self, *args: List[Any]) -> Any: """GET_PARAM Function""" if len(args) > 2: @@ -198,6 +210,8 @@ def COMPARE(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] == args[1] @@ -435,6 +449,8 @@ def GREATER_THAN_OR_EQUALS_TO(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] >= args[1] @@ -449,6 +465,8 @@ def GREATER_THAN(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] > args[1] @@ -463,6 +481,8 @@ def LESS_THAN_OR_EQUALS_TO(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] <= args[1] @@ -477,6 +497,8 @@ def LESS_THAN(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] < args[1] @@ -491,6 +513,8 @@ def DIFFERENT(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES.format(arg1=type(args[0]).__name__, arg2=type(args[1]).__name__) return args[0] != args[1] @@ -590,6 +614,8 @@ def INSIDE_RANGE(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None or args[2] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES_RANGES.format( arg1=type(args[0]).__name__, @@ -607,6 +633,8 @@ def OUTSIDE_RANGE(self, *args: List[Any]) -> str | None | bool: if args[0] is None or args[1] is None or args[2] is None: return None + args = self._standarize_datatypes(args) + if not isinstance(args[0], type(args[1])): return DIFFERENT_TYPES_RANGES.format( arg1=type(args[0]).__name__, diff --git a/pyproject.toml b/pyproject.toml index ed5e119..496b400 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "layrz-sdk" -version = "3.0.10" +version = "3.0.11" description = "Layrz SDK for Python" authors = [ {name = "Golden M, Inc.", email = "software@goldenm.com"} diff --git a/tests/test_lcl.py b/tests/test_lcl.py index 2c2d9b5..f25701c 100644 --- a/tests/test_lcl.py +++ b/tests/test_lcl.py @@ -541,7 +541,7 @@ def test_DIFFERENT(self) -> None: formula = 'DIFFERENT("Hola", 10)' lcl = LclCore(script=formula) result = self._process_and_convert(lcl) - self.assertEqual(result, 'Invalid data types - arg1: str - arg2: int') + self.assertEqual(result, 'Invalid data types - arg1: str - arg2: float') def test_HEX_TO_STR(self) -> None: formula = 'HEX_TO_STR("48656c6c6f")' From 5e4778c4f3f391ae6a194d774a57d89c72f6d798 Mon Sep 17 00:00:00 2001 From: Kenny Mochizuki Date: Tue, 9 Jul 2024 01:14:21 -0600 Subject: [PATCH 5/5] Added tzdata to requirements --- pyproject.toml | 1 + requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 496b400..0a1d3ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ classifiers = [ dependencies = [ "requests", "xlsxwriter", + "tzdata" ] [project.urls] diff --git a/requirements.txt b/requirements.txt index 3477048..acb5498 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests -xlsxwriter \ No newline at end of file +xlsxwriter +tzdata \ No newline at end of file