Skip to content

Commit

Permalink
fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bleykauf committed Jun 30, 2023
1 parent 699d6bd commit 24fa175
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: ./.github/actions/install-linien

- name: Install additional dependencies
run: pip install mypy types-appdirs pyqt5-stubs
run: pip install mypy types-appdirs pyqt5-stubs types-requests

- name: mypy for linien-common
run: mypy linien-common/linien_common
Expand Down
26 changes: 15 additions & 11 deletions linien-server/linien_server/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def start_logging(self, interval: float) -> None:
self.stop_event.clear()
self.thread = Thread(
target=self._logging_loop,
args=(interval),
args=(interval,),
daemon=True,
)
self.thread.start()
Expand All @@ -73,32 +73,36 @@ def _logging_loop(self, interval: float) -> None:
data[stat_name] = stat_value
else:
data[name] = param.value
self.write_data(data)
self.write_data(self.credentials, data)
sleep(interval)

def test_connection(self) -> Tuple[bool, int, str]:
def test_connection(
self, credentials: InfluxDBCredentials
) -> Tuple[bool, int, str]:
"""Write empty data to the server to test the connection"""
response = self.write_data({})
response = self.write_data(credentials, data={})
success = response.status_code == 204
return success, response.status_code, response.text

def write_data(self, data: dict) -> requests.Response:
def write_data(
self, credentials: InfluxDBCredentials, data: dict
) -> requests.Response:
"""Write data to the database"""
endpoint = self.credentials.url + "/api/v2/write"
endpoint = credentials.url + "/api/v2/write"
headers = {
"Authorization": "Token " + self.credentials.token,
"Authorization": "Token " + credentials.token,
"Content-Type": "text/plain; charset=utf-8",
"Accept": "application/json",
}
params = {
"org": self.credentials.org,
"bucket": self.credentials.bucket,
"org": credentials.org,
"bucket": credentials.bucket,
"precision": "ns",
}

data = self._convert_to_line_protocol(data)
point = self._convert_to_line_protocol(data)

response = requests.post(endpoint, headers=headers, params=params, data=data)
response = requests.post(endpoint, headers=headers, params=params, data=point)
return response

def _convert_to_line_protocol(self, data: dict) -> str:
Expand Down

0 comments on commit 24fa175

Please sign in to comment.