Skip to content

Commit

Permalink
Revert "fix: reorder of status fetch (#21)" (#25)
Browse files Browse the repository at this point in the history
This reverts commit d19c52c.
  • Loading branch information
kamiKAC authored Jun 16, 2024
1 parent cf6b71b commit b6d1b1d
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 42 deletions.
36 changes: 8 additions & 28 deletions .github/workflows/leaf2mqtt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 200
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v3
uses: docker/login-action@v1.10.0
with:
username: ${{ secrets.DOCKERHUBUSERNAME }}
password: ${{ secrets.DOCKERHUBACCESSTOKEN }}

- name: Get nearest tag
id: get-nearest-tag
if: ${{ github.ref != format('refs/heads/{0}', 'main') }}
shell: bash
run: |-
TAGS=$(git tag --list)
NEAREST_TAG=$(git describe --tags --abbrev=0)
SPECIFIC_TAG=$(git tag --points-at $(git rev-list -n 1 $NEAREST_TAG) | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+')
if [[ ! -z "$SPECIFIC_TAG" ]]; then
echo "Nearest tag is: $SPECIFIC_TAG"
echo "Using tag ${SPECIFIC_TAG}-edge"
echo "nearest_tag=${SPECIFIC_TAG}-edge" >> $GITHUB_OUTPUT
else
echo "Nearest tag not found, using 'edge' tag"
echo "nearest_tag=edge" >> $GITHUB_OUTPUT
fi

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
Expand All @@ -84,13 +65,12 @@ jobs:
tags: |
type=raw,value=${{ needs.release-please.outputs.tag_name }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{ steps.get-nearest-tag.outputs.nearest_tag }},enable=${{ github.ref != format('refs/heads/{0}', 'main') }}
type=raw,value=edge,enable=${{ github.ref != format('refs/heads/{0}', 'main') }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v2
with:
context: .
build-args: |
APP_VERSION=${{ steps.meta.outputs.version }}
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v8
tags: ${{ steps.meta.outputs.tags }}
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM dart:2.19.6-sdk AS build
ARG APP_VERSION=unknown

RUN apt-get update && \
apt-get install -y git
Expand All @@ -11,7 +10,7 @@ RUN dart pub get

COPY . .
RUN dart pub get --offline
RUN dart compile exe -DAPP_VERSION=${APP_VERSION} src/leaf_2_mqtt.dart -o src/leaf_2_mqtt
RUN dart compile exe src/leaf_2_mqtt.dart -o src/leaf_2_mqtt

FROM scratch
COPY --from=build /runtime/ /
Expand Down
168 changes: 168 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
blowfish_ecb:
dependency: transitive
description:
name: blowfish_ecb
sha256: ed01f5fcec0bd5ba04242263abd61ae0a01f4211f0aa79dd96367254a5cc5f59
url: "https://pub.dev"
source: hosted
version: "0.1.0"
clock:
dependency: transitive
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
source: hosted
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
sha256: ef7e3a5529178ce8f37a9d0b11cbbc8b1e025940f9cf9f76c42da6796301219d
url: "https://pub.dev"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
sha256: cf75650c66c0316274e21d7c43d3dea246273af5955bd94e8184837cd577575c
url: "https://pub.dev"
source: hosted
version: "3.0.1"
dartcarwings:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: f54dc13e1910d4e87db6555aef0398cc5e41903c
url: "https://github.com/Tobiaswk/dartcarwings"
source: git
version: "1.0.0"
dartnissanconnect:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: ed31b5a3ee6d472aea2a1fb97dbbcf8e90ef04c7
url: "https://gitlab.com/sensor-freak/dartnissanconnect"
source: git
version: "1.0.4"
dartnissanconnectna:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: f2a4335c1fdd605ac0d5444539496eedf85c807f
url: "https://gitlab.com/tobiaswkjeldsen/dartnissanconnectna"
source: git
version: "1.0.0"
event_bus:
dependency: transitive
description:
name: event_bus
sha256: "44baa799834f4c803921873e7446a2add0f3efa45e101a054b1f0ab9b95f8edc"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
http:
dependency: transitive
description:
name: http
sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
url: "https://pub.dev"
source: hosted
version: "0.13.6"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
intl:
dependency: transitive
description:
name: intl
sha256: "910f85bce16fb5c6f614e117efa303e85a1731bb0081edf3604a2ae6e9a3cc91"
url: "https://pub.dev"
source: hosted
version: "0.17.0"
logging:
dependency: "direct main"
description:
name: logging
sha256: "293ae2d49fd79d4c04944c3a26dfd313382d5f52e821ec57119230ae16031ad4"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
meta:
dependency: transitive
description:
name: meta
sha256: "5202fdd37b4da5fd14a237ed0a01cad6c1efd4c99b5b5a0d3c9237f3728c9485"
url: "https://pub.dev"
source: hosted
version: "1.7.0"
mqtt_client:
dependency: "direct main"
description:
name: mqtt_client
sha256: e3fab601bafebeb2cb10d1bc68ddc0b8de987aa5298515d518329c9d8a034257
url: "https://pub.dev"
source: hosted
version: "9.6.6"
path:
dependency: transitive
description:
name: path
sha256: "240ed0e9bd73daa2182e33c4efc68c7dd53c7c656f3da73515a2d163e151412d"
url: "https://pub.dev"
source: hosted
version: "1.8.1"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
sdks:
dart: ">=2.19.0 <3.0.0"
4 changes: 1 addition & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ dependencies:
url: https://github.com/kamiKAC/dartnissanconnect
ref: v1.0.5
dartcarwings:
git:
url: https://github.com/kamiKAC/dartcarwings
ref: v1.0.1
git: https://github.com/Tobiaswk/dartcarwings
mqtt_client: ^9.6.1
logging: ^1.0.1
environment:
Expand Down
15 changes: 6 additions & 9 deletions src/leaf_2_mqtt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ import 'mqtt_client_wrapper.dart';

LeafSession _session;
int _commandAttempts = 2;
const appVersion = String.fromEnvironment('APP_VERSION', defaultValue: 'unknown');

final Logger _log = Logger('main');

Future<void> main() async {
final Map<String, String> envVars = Platform.environment;

final String logLevelStr = envVars['LOG_LEVEL'] ?? '${Level.INFO}';
final String logLevelStr = envVars['LOG_LEVEL'] ?? '${Level.WARNING}';
Level logLevel =
Level.LEVELS.firstWhere(
(Level level) => level.name.toLowerCase() == logLevelStr.toLowerCase(),
orElse: () => null);

if (logLevel == null) {
print('LOG_LEVEL environment variable should be set to a valid value from: ${Level.LEVELS}. Defaulting to Info.');
logLevel = Level.INFO;
print('LOG_LEVEL environment variable should be set to a valid value from: ${Level.LEVELS}. Defaulting to Warning.');
logLevel = Level.WARNING;
}

Logger.root.level = logLevel;
Logger.root.onRecord.listen((LogRecord record) {
print('${record.level.name}: ${record.time}: ${record.loggerName}: ${record.message}');
});

_log.info('Version: ${appVersion}');
_log.info('V0.11');

final String leafUser = envVars['LEAF_USERNAME'];
final String leafPassword = envVars['LEAF_PASSWORD'];
Expand Down Expand Up @@ -275,10 +273,9 @@ Future<void> fetchAndPublishAllStatus(MqttClientWrapper mqttClient, String vin)
Future<void>(() => mqttClient.publishStates(
_session.executeSync((Vehicle vehicle) => vehicle.getVehicleStatus(), vin))),
fetchAndPublishBatteryStatus(mqttClient, vin),
fetchAndPublishCockpitStatus(mqttClient, vin),
fetchAndPublishClimateStatus(mqttClient, vin),
fetchAndPublishLocation(mqttClient, vin)

fetchAndPublishLocation(mqttClient, vin),
fetchAndPublishCockpitStatus(mqttClient, vin)
]);
}

Expand Down

0 comments on commit b6d1b1d

Please sign in to comment.