Skip to content

Commit

Permalink
upgrade github action ruff (#8)
Browse files Browse the repository at this point in the history
* upgrade github action ruff

* clean up issues from last PR where ruff failed (due to old version)
  • Loading branch information
brmurphy authored Feb 27, 2024
1 parent fed9bed commit c712c91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 42 deletions.
33 changes: 6 additions & 27 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
name: Python package

on: [push]

name: Ruff
on: [push, pull_request]
jobs:
build:

ruff:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
# default set of ruff rules with GitHub Annotations
ruff --format=github --target-version=py37 .
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1

29 changes: 14 additions & 15 deletions eero_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import eero as eero_api
import time
import cookie_store
import sys
from datetime import datetime

class JsonCollector(object):
Expand Down Expand Up @@ -99,7 +98,7 @@ def collect(self):
network_clients = eero_api_session.devices(network['url'])

# Global Labels and Values
label_values = [network['url'].split('/')[3], network["name"], network["nickname_label"] if network["nickname_label"] != None else network["name"] ]
label_values = [network_id, network["name"], network["nickname_label"] if network["nickname_label"] is not None else network["name"] ]

metrics["ssid"].add_metric(label_values, value = {"ssid" : network["name"]})

Expand Down Expand Up @@ -146,9 +145,9 @@ def collect(self):
if network_details["premium_dns"]["dns_policies"][policy]:
metrics["premium_dns_policies"].add_metric(label_values, value = {"policy" : policy})

metrics["last_reboot"].add_metric(label_values, datetime.timestamp(datetime.strptime(network_details["last_reboot"], "%Y-%m-%dT%H:%M:%S.%fZ")) if network_details["last_reboot"] != None else 0)
metrics["last_reboot"].add_metric(label_values, datetime.timestamp(datetime.strptime(network_details["last_reboot"], "%Y-%m-%dT%H:%M:%S.%fZ")) if network_details["last_reboot"] is not None else 0)

if network_details["homekit"] != None:
if network_details["homekit"] is not None:
metrics["homekit_enabled"].add_metric(label_values, 1 if network_details["homekit"]["enabled"] else 0)
metrics["homekit_managed_network"].add_metric(label_values, 1 if network_details["homekit"]["managedNetworkEnabled"] else 0)

Expand All @@ -166,8 +165,8 @@ def collect(self):
eero_label_values = [eero_id, eero_name] + label_values
metrics["eero_model"].add_metric(eero_label_values, value = {"model" : eero["model"]})
metrics["eero_model"].add_metric(eero_label_values, value = {"model_number" : eero["model_number"]})
metrics["eero_mesh_connection_quality"].add_metric(eero_label_values, eero["mesh_quality_bars"]/5 if eero["mesh_quality_bars"] != None else 0)
metrics["eero_mesh_connection_type"].add_metric(eero_label_values, value = {"connection" : eero["connection_type"] if eero["connection_type"] != None else "DISCONNECTED"})
metrics["eero_mesh_connection_quality"].add_metric(eero_label_values, eero["mesh_quality_bars"]/5 if eero["mesh_quality_bars"] is not None else 0)
metrics["eero_mesh_connection_type"].add_metric(eero_label_values, value = {"connection" : eero["connection_type"] if eero["connection_type"] is not None else "DISCONNECTED"})
metrics["eero_gateway"].add_metric(eero_label_values, 1 if eero["gateway"] else 0)
metrics["eero_status"].add_metric(eero_label_values, 1 if eero["status"] == "green" else 0)
metrics["eero_client_count"].add_metric(eero_label_values, eero["connected_clients_count"])
Expand All @@ -183,12 +182,12 @@ def collect(self):
ipv6_addresses.append(ipv6["address"])
metrics["eero_ipv6"].add_metric(eero_label_values, value = {"ipv6_address" : ", ".join(ipv6_addresses)})
metrics["eero_version"].add_metric(eero_label_values, value = {"version" : eero["os"]})
metrics["eero_last_reboot"].add_metric(eero_label_values, datetime.timestamp(datetime.strptime(eero["last_reboot"], "%Y-%m-%dT%H:%M:%S.%fZ")) if eero["last_reboot"] != None else 0)
metrics["eero_last_reboot"].add_metric(eero_label_values, datetime.timestamp(datetime.strptime(eero["last_reboot"], "%Y-%m-%dT%H:%M:%S.%fZ")) if eero["last_reboot"] is not None else 0)

for client in network_clients:
client_label_values = [client["mac"], client["hostname"] if client["hostname"] != None else "", client["display_name"] if client["display_name"] != None else "", client["source"]["url"].split('/')[3], client["source"]["location"]] + label_values
client_label_values = [client["mac"], client["hostname"] if client["hostname"] is not None else "", client["display_name"] if client["display_name"] is not None else "", client["source"]["url"].split('/')[3], client["source"]["location"]] + label_values
for detail in client_details_list:
if client[detail] != None:
if client[detail] is not None:
metrics["client_details"].add_metric(client_label_values, value = {detail : client[detail]})

for ip in client["ips"]:
Expand All @@ -203,15 +202,15 @@ def collect(self):
metrics["client_connection_quality"].add_metric(client_label_values, client["connectivity"]["score"])
metrics["client_connection_wireless_frequency"].add_metric(client_label_values, client["connectivity"]["frequency"])

metrics["client_rx_bandwidth"].add_metric(client_label_values, client["connectivity"]["rx_rate_info"]["rate_bps"] if client["connectivity"]["rx_rate_info"]["rate_bps"] != None else 0)
metrics["client_tx_bandwidth"].add_metric(client_label_values, client["connectivity"]["tx_rate_info"]["rate_bps"] if client["connectivity"]["tx_rate_info"]["rate_bps"] != None else 0)
metrics["client_rx_bandwidth"].add_metric(client_label_values, client["connectivity"]["rx_rate_info"]["rate_bps"] if client["connectivity"]["rx_rate_info"]["rate_bps"] is not None else 0)
metrics["client_tx_bandwidth"].add_metric(client_label_values, client["connectivity"]["tx_rate_info"]["rate_bps"] if client["connectivity"]["tx_rate_info"]["rate_bps"] is not None else 0)

for rx in client["connectivity"]["rx_rate_info"]:
if client["connectivity"]["rx_rate_info"][rx] != None:
if client["connectivity"]["rx_rate_info"][rx] is not None:
if rx != "rate_bps":
metrics["client_rx_connection_details"].add_metric(client_label_values, value = {str(rx) : str(client["connectivity"]["rx_rate_info"][rx])})
for tx in client["connectivity"]["tx_rate_info"]:
if client["connectivity"]["tx_rate_info"][tx] != None:
if client["connectivity"]["tx_rate_info"][tx] is not None:
if tx != "rate_bps":
metrics["client_tx_connection_details"].add_metric(client_label_values, value = {str(tx) : str(client["connectivity"]["tx_rate_info"][tx])})

Expand All @@ -220,8 +219,8 @@ def collect(self):
if not client["wireless"]:
metrics["client_wired_bandwidth"].add_metric(client_label_values, client["connectivity"]["ethernet_status"]["speed"][1:] * 1000000)

metrics['client_blacklisted'].add_metric(client_label_values, 0 if not client["blacklisted"] or client["blacklisted"] == None else 1)
metrics['client_paused'].add_metric(client_label_values, 0 if not client["paused"] or client["paused"] == None else 1)
metrics['client_blacklisted'].add_metric(client_label_values, 0 if not client["blacklisted"] or client["blacklisted"] is None else 1)
metrics['client_paused'].add_metric(client_label_values, 0 if not client["paused"] or client["paused"] is None else 1)

metrics["client_guest"].add_metric(client_label_values, 1 if client["is_guest"] else 0)

Expand Down

0 comments on commit c712c91

Please sign in to comment.