Initial import
This commit is contained in:
commit
b5d61674d8
13 changed files with 287 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.pre-commit-config.yaml
|
||||
result
|
||||
.direnv
|
||||
3
README.org
Normal file
3
README.org
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#+TITLE: Tankerkönig To MQTT gateway
|
||||
|
||||
* Tankerkönig to MQTT gateway
|
||||
6
app/tk2mqtt.hs
Normal file
6
app/tk2mqtt.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module Main (main) where
|
||||
|
||||
import TK2MQTT qualified
|
||||
|
||||
main :: IO ()
|
||||
main = TK2MQTT.defaultMain
|
||||
79
flake.lock
generated
Normal file
79
flake.lock
generated
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1659877975,
|
||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1644229661,
|
||||
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1661626419,
|
||||
"narHash": "sha256-CjdPtdwH7I5Es4SjdCGuNfeulIyaM1LP0dXGWi4dyuQ=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a5e05d62460ff0b7627559a8b55ab421041ebf0a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pre-commit-hooks": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1660830093,
|
||||
"narHash": "sha256-HUhx3a82C7bgp2REdGFeHJdhEAzMGCk3V8xIvfBqg1I=",
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"rev": "8cb8ea5f1c7bc2984f460587fddd5f2e558f6eb8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "pre-commit-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": "pre-commit-hooks"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
78
flake.nix
Normal file
78
flake.nix
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
description = "Tankerkönig-to-MQTT gateway";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
||||
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }:
|
||||
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
overlay = final: prev: {
|
||||
tk2mqtt = final.callCabal2nix "tk2mqtt" ./. { };
|
||||
};
|
||||
|
||||
haskellPackages = pkgs.haskell.packages.ghc924.extend overlay;
|
||||
in {
|
||||
packages.default = haskellPackages.tk2mqtt;
|
||||
|
||||
apps = {
|
||||
# run with: nix run #.tk2mqtt
|
||||
tk2mqtt = {
|
||||
type = "app";
|
||||
program = "${self.packages.${system}.default}/bin/tk2mqtt";
|
||||
};
|
||||
|
||||
# run with: nix run
|
||||
default = self.apps.${system}.tk2mqtt;
|
||||
};
|
||||
|
||||
checks = {
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
settings = { ormolu.defaultExtensions = [ "GHC2021" ]; };
|
||||
tools.fourmolu = haskellPackages.fourmolu;
|
||||
hooks = {
|
||||
nixfmt.enable = true;
|
||||
fourmolu.enable = true;
|
||||
hpack.enable = true;
|
||||
hlint.enable = true;
|
||||
doctest = {
|
||||
enable = false;
|
||||
name = "Run documentation tests";
|
||||
entry = "${haskellPackages.doctest}/bin/doctest src app";
|
||||
files = "\\.l?hs$";
|
||||
pass_filenames = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
devShells.default = haskellPackages.shellFor {
|
||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
||||
|
||||
packages = p: [ p.tk2mqtt ];
|
||||
|
||||
withHoogle = true;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
haskellPackages.haskell-language-server
|
||||
haskellPackages.fourmolu
|
||||
haskellPackages.hspec-discover
|
||||
haskellPackages.doctest
|
||||
cabal-install
|
||||
ghcid
|
||||
nixfmt
|
||||
hpack
|
||||
hlint
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
||||
2
fourmolu.yaml
Normal file
2
fourmolu.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
haddock-style: single-line
|
||||
indentation: 2
|
||||
64
package.yaml
Normal file
64
package.yaml
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
name: tk2mqtt
|
||||
version: 0.0.1.0
|
||||
license: MIT
|
||||
author: "Alexander Kobjolke"
|
||||
maintainer: "alex@jakalx.net"
|
||||
copyright: "Alexander Kobjolke 2023"
|
||||
description: "Tankerkönig-to-MQTT gateway"
|
||||
|
||||
extra-source-files:
|
||||
- README.org
|
||||
|
||||
dependencies:
|
||||
- base >= 4.13 && < 5
|
||||
- time
|
||||
- directory
|
||||
- containers
|
||||
- net-mqtt
|
||||
- req
|
||||
- aeson
|
||||
- text
|
||||
# - bytestring
|
||||
|
||||
ghc-options:
|
||||
- -Wall
|
||||
- -fdefer-typed-holes
|
||||
|
||||
default-extensions:
|
||||
- BlockArguments
|
||||
- OverloadedStrings
|
||||
- ImportQualifiedPost
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
verbatim:
|
||||
default-language: GHC2021
|
||||
|
||||
executables:
|
||||
tk2mqtt:
|
||||
source-dirs: app
|
||||
main: tk2mqtt.hs
|
||||
dependencies:
|
||||
- tk2mqtt
|
||||
verbatim:
|
||||
default-language: GHC2021
|
||||
|
||||
tests:
|
||||
spec:
|
||||
cpp-options: -DTEST
|
||||
main: Spec.hs
|
||||
source-dirs:
|
||||
- test/spec
|
||||
dependencies:
|
||||
- tk2mqtt
|
||||
- hspec
|
||||
- QuickCheck
|
||||
- quickcheck-instances
|
||||
build-tools: hspec-discover
|
||||
verbatim:
|
||||
default-language: GHC2021
|
||||
doctest:
|
||||
main: Doctest.hs
|
||||
source-dirs:
|
||||
- test/doctest
|
||||
build-tools: doctest
|
||||
26
src/TK2MQTT.hs
Normal file
26
src/TK2MQTT.hs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{-# LANGUAGE RecordWildCards #-}
|
||||
|
||||
module TK2MQTT (
|
||||
runTK2MQTT,
|
||||
defaultMain,
|
||||
) where
|
||||
|
||||
import System.Environment qualified as Env
|
||||
import System.IO
|
||||
|
||||
import Control.Exception qualified as Exception
|
||||
import System.IO.Error qualified as IOError
|
||||
|
||||
runTK2MQTT :: IO ()
|
||||
runTK2MQTT = do
|
||||
putStrLn "Hello"
|
||||
|
||||
eitherToError :: Show a => Either a b -> IO b
|
||||
eitherToError = either (Exception.throwIO . IOError.userError . show) return
|
||||
|
||||
handleError :: IOError -> IO ()
|
||||
handleError e = do
|
||||
hPutStrLn stderr $ "I ran into an issue: " <> show e
|
||||
|
||||
defaultMain :: IO ()
|
||||
defaultMain = Exception.catch runTK2MQTT handleError
|
||||
2
src/TK2MQTT/Internal.hs
Normal file
2
src/TK2MQTT/Internal.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
-- | Internal module in order to facilitate testability.
|
||||
module TK2MQTT.Internal where
|
||||
10
test/doctest/Doctest.hs
Normal file
10
test/doctest/Doctest.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
-- | Rn the doctest executable
|
||||
module Main where
|
||||
|
||||
import System.Process (callProcess)
|
||||
|
||||
doctest :: [String] -> IO ()
|
||||
doctest = callProcess "doctest"
|
||||
|
||||
main :: IO ()
|
||||
main = doctest ["--fast", "src"]
|
||||
1
test/spec/Spec.hs
Normal file
1
test/spec/Spec.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
|
||||
12
test/spec/TK2MQTTSpec.hs
Normal file
12
test/spec/TK2MQTTSpec.hs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
module TK2MQTTSpec (spec) where
|
||||
|
||||
import HCat.Internal
|
||||
|
||||
import Test.Hspec
|
||||
import Test.Hspec.QuickCheck (prop)
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "parseArgs" do
|
||||
it "returns the filename if given a single argument" do
|
||||
True `shouldBe` True
|
||||
Loading…
Add table
Add a link
Reference in a new issue