aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Eriksen <d@ennis.no>2023-11-02 12:44:44 +0100
committerDennis Eriksen <d@ennis.no>2023-11-02 12:44:44 +0100
commit3eddd39a5aa52d40fbc2e0a12b463d270ddfeba2 (patch)
treeb7f4559cf252a32990f5e462dc09b2a9ad23c9b4
parentadd comment about manual starttime (diff)
downloadenergyscripts-3eddd39a5aa52d40fbc2e0a12b463d270ddfeba2.tar.gz
adding linting with ruff
-rw-r--r--pyproject.toml54
-rw-r--r--scripts/common/__init__.py2
-rw-r--r--scripts/common/postgres.py1
-rw-r--r--scripts/common/queue.py3
-rw-r--r--scripts/elvia.py7
-rw-r--r--scripts/elvia_gridtariff.py7
-rw-r--r--scripts/entsoe.py10
-rw-r--r--scripts/esphomeapi.py16
-rw-r--r--scripts/mqtt_listener.py6
-rw-r--r--scripts/mqtt_watch.py3
-rw-r--r--scripts/nb.py9
-rw-r--r--scripts/neohub.py6
-rw-r--r--scripts/queue_runner.py4
-rw-r--r--scripts/tibber_consumption.py8
-rw-r--r--scripts/tibber_prices.py8
-rw-r--r--scripts/yr.py2
16 files changed, 96 insertions, 50 deletions
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..241d61a
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,54 @@
+[tool.ruff]
+# https://docs.astral.sh/ruff/rules/
+# Enable:
+# Pyflakes (`F`)
+# Pycodestyle (`E`)
+# Whitespace-warnings (`W`)
+# isort (`I`)
+select = ["E", "F", "W", "I"]
+
+# E501 too long lines
+# F403 star-imports
+# F405 undefined functions as a result of star-imports
+# W191 tab indents - `ruff format` recommends this be ignored
+ignore = ["E501", "F403", "F405", "W191"]
+
+# Allow fix for all enabled rules (when `--fix`) is provided.
+fixable = ["ALL"]
+unfixable = []
+
+# Exclude a variety of commonly ignored directories.
+exclude = [
+ ".bzr",
+ ".direnv",
+ ".eggs",
+ ".git",
+ ".git-rewrite",
+ ".hg",
+ ".mypy_cache",
+ ".nox",
+ ".pants.d",
+ ".pytype",
+ ".ruff_cache",
+ ".svn",
+ ".tox",
+ ".venv",
+ "__pypackages__",
+ "_build",
+ "buck-out",
+ "build",
+ "dist",
+ "node_modules",
+ "venv",
+]
+per-file-ignores = {}
+
+# Same as Black.
+line-length = 88
+
+# Allow unused variables when underscore-prefixed.
+dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
+
+# Assume Python 3.10
+target-version = "py310"
+
diff --git a/scripts/common/__init__.py b/scripts/common/__init__.py
index f97635b..83f1b66 100644
--- a/scripts/common/__init__.py
+++ b/scripts/common/__init__.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
''' common functions and stuff '''
+import logging
import os
import sys
-import logging
from datetime import datetime
QUEUE = bool(os.environ.get('el_QUEUE', False))
diff --git a/scripts/common/postgres.py b/scripts/common/postgres.py
index bff4a84..efa4b5a 100644
--- a/scripts/common/postgres.py
+++ b/scripts/common/postgres.py
@@ -3,6 +3,7 @@
import os
import sys
+
import psycopg
pg_db = os.environ['el_pg_db']
diff --git a/scripts/common/queue.py b/scripts/common/queue.py
index 35abeaa..4510d55 100644
--- a/scripts/common/queue.py
+++ b/scripts/common/queue.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python3
''' common functions and stuff '''
+import logging
import os
import pickle
-import logging
+
from litequeue import SQLQueue
QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')
diff --git a/scripts/elvia.py b/scripts/elvia.py
index dab2329..b74f784 100644
--- a/scripts/elvia.py
+++ b/scripts/elvia.py
@@ -3,12 +3,11 @@
import os
import sys
-from datetime import datetime
-from datetime import timedelta
-from tzlocal import get_localzone
-import requests
+from datetime import datetime, timedelta
import common
+import requests
+from tzlocal import get_localzone
apiKey = os.environ['el_elvia_token']
apiUrl = "https://elvia.azure-api.net/customer/metervalues/api/v1/metervalues"
diff --git a/scripts/elvia_gridtariff.py b/scripts/elvia_gridtariff.py
index 43f1940..720336b 100644
--- a/scripts/elvia_gridtariff.py
+++ b/scripts/elvia_gridtariff.py
@@ -3,12 +3,11 @@
import os
import sys
-from datetime import datetime
-from datetime import timedelta
-from tzlocal import get_localzone
-import requests
+from datetime import datetime, timedelta
import common
+import requests
+from tzlocal import get_localzone
# API documentation: https://elvia.portal.azure-api.net/docs/services/gridtariffapi/operations/post-digin-api-v-tariffquery-meteringpointsgridtariffs?
diff --git a/scripts/entsoe.py b/scripts/entsoe.py
index b1d9270..70a1f19 100644
--- a/scripts/entsoe.py
+++ b/scripts/entsoe.py
@@ -3,15 +3,13 @@
import os
import sys
-from datetime import datetime
-from datetime import timedelta
+from datetime import datetime, timedelta
+
+import common
import requests
import xmltodict
-from tzlocal import get_localzone
from dateutil import tz
-
-import common
-
+from tzlocal import get_localzone
# variables
diff --git a/scripts/esphomeapi.py b/scripts/esphomeapi.py
index 57f4ebc..5fcbe37 100644
--- a/scripts/esphomeapi.py
+++ b/scripts/esphomeapi.py
@@ -1,18 +1,18 @@
#!/usr/bin/env python3
''' Check on esphome-devices '''
-import os
-import sys
-from datetime import datetime
-from aioesphomeapi import APIClient, ReconnectLogic, SensorState, APIConnectionError
-import asyncio
import argparse
+import asyncio
import logging
-#import colorlog
-import zeroconf
+import os
+import sys
import common
+#import colorlog
+import zeroconf
+from aioesphomeapi import APIClient, APIConnectionError, ReconnectLogic, SensorState
+
sleepsec = 60
noise_psk = os.environ['el_esphome_api_psk']
@@ -56,7 +56,7 @@ async def main(args):
await api.disconnect()
def callback(state):
- if type(state) == SensorState and state.missing_state == False:
+ if type(state) == SensorState and state.missing_state is False:
log.debug('function callback(' + str(state) + ')')
sensor = sensors[state.key]
diff --git a/scripts/mqtt_listener.py b/scripts/mqtt_listener.py
index 48dfc6f..981c40a 100644
--- a/scripts/mqtt_listener.py
+++ b/scripts/mqtt_listener.py
@@ -1,12 +1,12 @@
#!/usr/bin/env python3
''' Listen for mqtt-events, and trigger for some '''
-import os
import json
+import os
from datetime import datetime
-import paho.mqtt.client as mqtt
import common
+import paho.mqtt.client as mqtt
mqtt_server = os.environ['el_mqtt_server']
mqtt_port = int(os.environ['el_mqtt_port'])
@@ -64,7 +64,7 @@ def on_message(client, userdata, msg):
common.statein(name, data['temperature'], 'temperature', '°C', verbose=True)
if 'humidity' in data:
common.statein(name, data['humidity'], 'humidity', '%', verbose=True)
-
+
diff --git a/scripts/mqtt_watch.py b/scripts/mqtt_watch.py
index d61ecc0..a845d30 100644
--- a/scripts/mqtt_watch.py
+++ b/scripts/mqtt_watch.py
@@ -3,9 +3,8 @@
import os
from datetime import datetime
-import paho.mqtt.client as mqtt
-import common
+import paho.mqtt.client as mqtt
mqtt_server = os.environ['el_mqtt_server']
mqtt_port = int(os.environ['el_mqtt_port'])
diff --git a/scripts/nb.py b/scripts/nb.py
index c3bbe40..2e2a7f9 100644
--- a/scripts/nb.py
+++ b/scripts/nb.py
@@ -1,16 +1,15 @@
#!/usr/bin/env python3
''' Get exchange rates from nb '''
+import csv
import os
import sys
-import csv
import tempfile
-from datetime import datetime
-from datetime import timedelta
-from tzlocal import get_localzone
-import requests
+from datetime import datetime, timedelta
import common
+import requests
+from tzlocal import get_localzone
# I'm not sure I understand Norges Banks json-model. It seems a lot easier to just get the CSV, and convert it to JSON.
apiUrl = "https://data.norges-bank.no/api/data/EXR/B.EUR.NOK.SP?format=csv&locale=en"
diff --git a/scripts/neohub.py b/scripts/neohub.py
index f2c0ed8..e15a00e 100644
--- a/scripts/neohub.py
+++ b/scripts/neohub.py
@@ -1,13 +1,13 @@
#!/usr/bin/python3
''' Get stuff from neohub! This is mostly the usage-example from https://gitlab.com/neohubapi/neohubapi/ '''
+import asyncio
import os
import time
-import asyncio
from datetime import datetime
-import neohubapi.neohub as neohub
import common
+import neohubapi.neohub as neohub
neohub_ip = os.environ['el_neohub_ip']
neohub_port = os.environ['el_neohub_port']
@@ -19,7 +19,7 @@ async def call_neohub():
hub = neohub.NeoHub(neohub_ip, int(neohub_port))
# Or, for a websocket connection:
# hub = neohub.Neohub(port=4243, token='xxx-xxxxxxx')
- system = await hub.get_system()
+ # system = await hub.get_system()
hub_data, devices = await hub.get_live_data()
for device in devices['thermostats']:
#print(f"Temperature in zone {device.name}: {device}")
diff --git a/scripts/queue_runner.py b/scripts/queue_runner.py
index 0264d83..9ed52f2 100644
--- a/scripts/queue_runner.py
+++ b/scripts/queue_runner.py
@@ -2,12 +2,12 @@
''' move items from queue to database '''
import os
-import time
import pickle
import sqlite3
-from litequeue import SQLQueue
+import time
from common.postgres import dbi
+from litequeue import SQLQueue
QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')
QUEUE_DIR = os.environ.get('el_QUEUE_dir', 'queue')
diff --git a/scripts/tibber_consumption.py b/scripts/tibber_consumption.py
index 01732d0..b88d00b 100644
--- a/scripts/tibber_consumption.py
+++ b/scripts/tibber_consumption.py
@@ -3,13 +3,11 @@
import os
import sys
-from datetime import datetime
-from datetime import timedelta
-from tzlocal import get_localzone
-import requests
+from datetime import datetime, timedelta
import common
-
+import requests
+from tzlocal import get_localzone
# variables
apiKey = os.environ['el_tibber_token']
diff --git a/scripts/tibber_prices.py b/scripts/tibber_prices.py
index 809a74c..af839bd 100644
--- a/scripts/tibber_prices.py
+++ b/scripts/tibber_prices.py
@@ -3,13 +3,11 @@
import os
import sys
-from datetime import datetime
-from datetime import timedelta
-from tzlocal import get_localzone
-import requests
+from datetime import datetime, timedelta
import common
-
+import requests
+from tzlocal import get_localzone
# variables
apiKey = os.environ['el_tibber_token']
diff --git a/scripts/yr.py b/scripts/yr.py
index 9ec04d7..6d53d5c 100644
--- a/scripts/yr.py
+++ b/scripts/yr.py
@@ -3,9 +3,9 @@
import os
import sys
-import requests
import common
+import requests
location = int(os.environ['el_location'])
lat = str(os.environ['el_yr_lat'])