Skip to content

Commit

Permalink
feat: initial release (#2)
Browse files Browse the repository at this point in the history
* got most of the things I want working to work

* set line paths back to original settings

* remove carbon stuffs

* create some reusable code and add battery to home

* simplify naming and create reusable function for getting a number to a single fractional digit

* set animation duration to 3s until I can find a nice calculation

* add grid to home circle

* do actual rounding instead of just formating

* ensure hass exists

* huge refactor to go to from 7 entities to 4

* a decent duration calc

* always show in/out values on battery and grid

* implement home circumference border

* remove battery to grid line

* circle rate tweaks

* move each line/circle flow into it's own svg

* centralize duration calculations

* fix type in flow id

* smooth out duration changes

* add some workflows and hacs stuff

* remove hacs integration validation

* fix yaml typo

* Add build script

* add readme

* add description and keywords

* update hacs file

* add more scripts

* add semantic-release

* Update README.md
  • Loading branch information
ulic75 authored Apr 27, 2022
1 parent 2db97f4 commit 93e9da1
Show file tree
Hide file tree
Showing 13 changed files with 2,129 additions and 97 deletions.
8 changes: 1 addition & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ module.exports = {
"@typescript-eslint/no-unused-vars": ["warn"],
"class-methods-use-this": "off",
"import/no-unresolved": "off",
"import/extensions": [
"error",
"always",
{
ignorePackages: true,
},
],
"no-use-before-define": ["error", { functions: false }],
"lines-between-class-members": "off",
},
};
33 changes: 33 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI
on:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache pnpm modules
id: cache-modules
uses: actions/cache@v2
with:
path: |
~/.pnpm-store
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'rollup.config.js') }}
restore-keys: |
${{ runner.os }}-
- name: Setup pnpm
uses: pnpm/action-setup@v2.2.1
with:
version: latest
run_install: false

- name: Install Packages
if: steps.cache-modules.outputs.cache-hit != 'true'
run: pnpm install

- name: Build
run: pnpm build
44 changes: 44 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on: workflow_dispatch

jobs:
release-bundle:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev'

outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}

steps:
- uses: actions/checkout@v3

- name: Cache pnpm modules
id: cache-modules
uses: actions/cache@v2
with:
path: |
~/.pnpm-store
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml', 'rollup.config.js') }}
restore-keys: |
${{ runner.os }}-
- name: Setup pnpm
uses: pnpm/action-setup@v2.2.1
with:
version: latest
run_install: false

- name: Install Packages
if: steps.cache-modules.outputs.cache-hit != 'true'
run: pnpm install

- name: Build
run: pnpm build

- name: Release
run: pnpx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/semantic-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Semantic PR"
description: Ensure your PR title matches the Conventional Commits spec (https://www.conventionalcommits.org/).

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: HACS Validation

on:
pull_request:
jobs:
hacs:
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: "actions/checkout@v2"
- name: Validate HACS
uses: "hacs/action@main"
with:
category: "plugin"
19 changes: 19 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
branches: ["main", { name: "dev", prerelease: true }],
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/git",
{
assets: ["CHANGELOG.md", "README.md", "package.json", "pnpm-lock.yaml"],
},
],
[
"@semantic-release/github",
{
assets: "dist/*.js",
},
],
],
};
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Realtime Energy Distribution Card

This card for [Home Assistant](https://github.com/home-assistant/home-assistant) Dashboard card is designed to mimic the historic distribution card included by Home Assistant.

The card works with entities from within the **sensor** & **binary_sensor** domain and displays the sensors current state as well as a line graph representation of the history.

![realtime-distribution-preview](https://user-images.githubusercontent.com/5641964/165636264-dc2e02ed-e550-4167-9ce4-3dcbd7a84272.png)

## Install

### HACS (recommended)

This card is available in [HACS](https://hacs.xyz/) (Home Assistant Community Store).
<small>_HACS is a third party community store and is not included in Home Assistant out of the box._</small>

### Manual install

1. Download and copy `realtime-energy-distribution-card.js` from the [latest release](https://github.com/ulic75/realtime-energy-distribution-card/releases/latest) into your `config/www` directory.

2. Add the resource reference as decribed below.

### Add resource reference

If you configure Dashboards via YAML, add a reference to `realtime-energy-distribution-card.js` inside your `configuration.yaml`:

```yaml
resources:
- url: /local/realtime-energy-distribution-card.js
type: module
```
Else, if you prefer the graphical editor, use the menu to add the resource:
1. Make sure, advanced mode is enabled in your user profile (click on your user name to get there)
2. Navigate to Configuration -> Dashboards -> Resources Tab. Hit (+ ADD RESOURCE) icon
3. Enter URL `/local/realtime-energy-distribution-card.js` and select type "JavaScript Module".
(Use `/hacsfiles/realtime-energy-distribution-card/realtime-energy-distribution-card.js` and select "JavaScript Module" for HACS install)
4. Restart Home Assistant.

## Using the card

We recommend looking at the [Example usage section](#example-usage) to understand the basics to configure this card.
(also) pay attention to the **required** options mentioned below.

### Options

#### Card options

| Name | Type | Default | Description |
| ------------------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------- |
| type **_(required)_** | string | | `custom:realtime-energy-distribution-card`. |
| entities **_(required)_** | map | | One or more sensor entities in a list, see [entities map](#entities-map) for additional entity options. |
| |

#### Entities map

| Name | Unit | Description |
| ------------------------ | :--: | -------------------------------------------------------------------------------------- |
| battery **_(required)_** | kW | Entity providing a positive value when charging and a negative value when discharging. |
| battery_charge | % | Entity providing the current percentage of charge on the battery. |
| grid **_(required)_** | kW | Entity providing a positive value when consuming and a negative value when producting. |
| solar **_(required)_** | kW | Entity providing a value of generation. |

### Example usage

```yaml
type: custom:realtime-energy-distribution-card
title: Realtime Distribution
entities:
battery: sensor.powerwall_battery_now
battery_charge: sensor.powerwall_charge
grid: sensor.powerwall_site_now
solar: sensor.powerwall_solar_now
```
4 changes: 4 additions & 0 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "realtime-energy-distribution-card",
"render_readme": true
}
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"name": "realtime-energy-distribution-card",
"version": "1.0.0",
"description": "",
"description": "A realtime energy distribution card for Home Assistant",
"keywords": [
"home-assistant",
"homeassistant",
"hass",
"dashboard",
"custom-cards"
],
"main": "index.js",
"repository": {
"type": "git",
Expand All @@ -13,6 +20,11 @@
"url": "https://github.com/ulic75/realtime-energy-distribution-card/issues"
},
"homepage": "https://github.com/ulic75/realtime-energy-distribution-card#readme",
"scripts": {
"build": "rollup -c",
"lint": "eslint src/*",
"watch": "rollup -wc"
},
"dependencies": {
"@mdi/js": "^6.6.96",
"custom-card-helpers": "^1.9.0",
Expand All @@ -29,6 +41,7 @@
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-typescript": "^8.3.2",
"@semantic-release/git": "^10.0.1",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"eslint": "^8.14.0",
Expand All @@ -37,6 +50,7 @@
"rollup": "^2.70.2",
"rollup-plugin-serve": "^1.1.0",
"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^19.0.2",
"typescript": "^4.6.3"
}
}
Loading

0 comments on commit 93e9da1

Please sign in to comment.