Convert Resource class to dataclass
This commit is contained in:
parent
b9163ccfe6
commit
f037ed5c24
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import dataclasses
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
@ -11,10 +12,10 @@ import nagiosplugin
|
|||||||
_log = logging.getLogger("nagiosplugin")
|
_log = logging.getLogger("nagiosplugin")
|
||||||
|
|
||||||
|
|
||||||
class Batteries(nagiosplugin.Resource):
|
@dataclasses.dataclass
|
||||||
def __init__(self, url: str, token: str):
|
class Entities(nagiosplugin.Resource):
|
||||||
self.url = url
|
url: str
|
||||||
self.token = token
|
token: str
|
||||||
|
|
||||||
def hass_get(self, endpoint: str) -> requests.Response:
|
def hass_get(self, endpoint: str) -> requests.Response:
|
||||||
headers = {
|
headers = {
|
||||||
@ -79,7 +80,7 @@ def main():
|
|||||||
args = argp.parse_args()
|
args = argp.parse_args()
|
||||||
|
|
||||||
check = nagiosplugin.Check(
|
check = nagiosplugin.Check(
|
||||||
Batteries(args.url, args.token),
|
Entities(args.url, args.token),
|
||||||
nagiosplugin.ScalarContext("battery", args.warning, args.critical),
|
nagiosplugin.ScalarContext("battery", args.warning, args.critical),
|
||||||
)
|
)
|
||||||
check.main(args.verbose)
|
check.main(args.verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user