Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #44

Merged
merged 6 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/hassfest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
- cron: '0 0 * * *'

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "home-assistant/actions/hassfest@master"
- uses: "actions/checkout@v3"
- uses: "home-assistant/actions/hassfest@master"
102 changes: 51 additions & 51 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,62 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Replace version and service in release_const.py
working-directory: ./custom_components/oig_cloud
run: |
echo 'COMPONENT_VERSION = "${{ github.event.inputs.version }}"' > release_const.py
if [ "${{ github.event.inputs.version }}" == "dev" ]; then
echo 'SERVICE_NAME = "oig_cloud_dev"' >> release_const.py
else
echo 'SERVICE_NAME = "oig_cloud"' >> release_const.py
fi
- name: Replace version and service in release_const.py
working-directory: ./custom_components/oig_cloud
run: |
echo 'COMPONENT_VERSION = "${{ github.event.inputs.version }}"' > release_const.py
if [ "${{ github.event.inputs.version }}" == "dev" ]; then
echo 'SERVICE_NAME = "oig_cloud_dev"' >> release_const.py
else
echo 'SERVICE_NAME = "oig_cloud"' >> release_const.py
fi

- name: Update version property in manifest.json
working-directory: ./custom_components/oig_cloud
run: |
if [ "${{ github.event.inputs.version }}" == "dev" ]; then
jq --arg version '0.0.0' '.version = $version' manifest.json > manifest.tmp && mv manifest.tmp manifest.json
else
jq --arg version ${{ github.event.inputs.version }} '.version = $version' manifest.json > manifest.tmp && mv manifest.tmp manifest.json
fi
- name: Update version property in manifest.json
working-directory: ./custom_components/oig_cloud
run: |
if [ "${{ github.event.inputs.version }}" == "dev" ]; then
jq --arg version '0.0.0' '.version = $version' manifest.json > manifest.tmp && mv manifest.tmp manifest.json
else
jq --arg version ${{ github.event.inputs.version }} '.version = $version' manifest.json > manifest.tmp && mv manifest.tmp manifest.json
fi


- name: Commit changes
working-directory: ./custom_components/oig_cloud
run: |
git config --global user.name "Pavel Simsa"
git config --global user.email "[email protected]"
git add release_const.py manifest.json
git commit -m "Setting release variables to ${{ github.event.inputs.version }}"
- name: Commit changes
working-directory: ./custom_components/oig_cloud
run: |
git config --global user.name "Pavel Simsa"
git config --global user.email "[email protected]"
git add release_const.py manifest.json
git commit -m "Setting release variables to ${{ github.event.inputs.version }}"

- name: Push changes
working-directory: ./custom_components/oig_cloud
if: ${{ github.event.inputs.create-tag != 'true' }}
run: |
git push

- name: Create tag
if: ${{ github.event.inputs.create-tag == 'true' }}
working-directory: ./custom_components/oig_cloud
run: |
git tag -a v${{ github.event.inputs.version }} -m "Version ${{ github.event.inputs.version }}"
git push --tags
- name: Push changes
working-directory: ./custom_components/oig_cloud
if: ${{ github.event.inputs.create-tag != 'true' }}
run: |
git push

- name: Create draft release
uses: actions/create-release@v1
if: ${{ github.event.inputs.create-tag == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.event.inputs.version }}
release_name: Release ${{ github.event.inputs.version }}
draft: true
- name: Create tag
if: ${{ github.event.inputs.create-tag == 'true' }}
working-directory: ./custom_components/oig_cloud
run: |
git tag -a v${{ github.event.inputs.version }} -m "Version ${{ github.event.inputs.version }}"
git push --tags

- name: Create draft release
uses: actions/create-release@v1
if: ${{ github.event.inputs.create-tag == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.event.inputs.version }}
release_name: Release ${{ github.event.inputs.version }}
draft: true

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![GitHub Release Date - Published_At](https://img.shields.io/github/release-date/psimsa/oig_cloud)
[![Validate with hassfest](https://github.com/psimsa/oig_cloud/actions/workflows/hassfest.yml/badge.svg)](https://github.com/psimsa/oig_cloud/actions/workflows/hassfest.yml)
[![HACS Action](https://github.com/psimsa/oig_cloud/actions/workflows/hacs.yml/badge.svg)](https://github.com/psimsa/oig_cloud/actions/workflows/hacs.yml)
[![CodeFactor](https://www.codefactor.io/repository/github/psimsa/oig_cloud/badge)](https://www.codefactor.io/repository/github/psimsa/oig_cloud)

---
# OIG Cloud Integrace pro Home Assistant
Expand Down
4 changes: 2 additions & 2 deletions custom_components/oig_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async def async_setup_entry(
no_telemetry = entry.data[CONF_NO_TELEMETRY]

if no_telemetry is False:
email_hash = hashlib.md5(username.encode("utf-8")).hexdigest()
hass_id = hashlib.md5(hass.data["core.uuid"].encode("utf-8")).hexdigest()
email_hash = hashlib.sha256(username.encode("utf-8")).hexdigest()
hass_id = hashlib.sha256(hass.data["core.uuid"].encode("utf-8")).hexdigest()

setup_tracing(email_hash, hass_id)
api_logger = logging.getLogger(oig_cloud_api.__name__)
Expand Down
101 changes: 53 additions & 48 deletions custom_components/oig_cloud/oig_cloud_computed_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


class OigCloudComputedSensor(OigCloudSensor):

@property
def state(self):
_LOGGER.debug(f"Getting state for {self.entity_id}")
Expand All @@ -52,62 +51,68 @@ def state(self):
return float(pv_data["dc_in"]["fv_p1"] + pv_data["dc_in"]["fv_p2"])

if self._node_id == "boiler" or self._sensor_type == "boiler_current_w":
if len(pv_data["boiler"]) > 0 and pv_data["boiler"]["p"] is not None:
# Spotreba bojleru
if (
self._sensor_type == "boiler_current_w"
and pv_data["boiler"]["p"] > 0
and (
pv_data["ac_in"]["aci_wr"]
+ pv_data["ac_in"]["aci_ws"]
+ pv_data["ac_in"]["aci_wt"]
)
< 0
):
return float(
pv_data["boiler"]["p"]
+ (
pv_data["ac_in"]["aci_wr"]
+ pv_data["ac_in"]["aci_ws"]
+ pv_data["ac_in"]["aci_wt"]
)
)
elif self._sensor_type == "boiler_current_w":
return float(pv_data["boiler"]["p"])
else:
return None
return self._get_boiler_consumption(pv_data)

# Spotreba CBB
if self._sensor_type == "cbb_consumption_w":
boiler_p = 0
return self._get_cbb_consumption(pv_data)

return None

def _get_cbb_consumption(self, pv_data) -> float:
boiler_p = 0
if (
len(pv_data["boiler"]) > 0
and pv_data["boiler"]["p"] is not None
and pv_data["boiler"]["p"] > 0
):
boiler_p = pv_data["boiler"]["p"]
return float(
# Výkon FVE
(pv_data["dc_in"]["fv_p1"] + pv_data["dc_in"]["fv_p2"])
-
# Spotřeba bojleru
boiler_p
-
# Spotřeba zátěž
pv_data["ac_out"]["aco_p"]
+
# Odběr ze sítě
(
pv_data["ac_in"]["aci_wr"]
+ pv_data["ac_in"]["aci_ws"]
+ pv_data["ac_in"]["aci_wt"]
)
+
# Nabíjení/vybíjení baterie
(pv_data["batt"]["bat_i"] * pv_data["batt"]["bat_v"] * -1)
)

def _get_boiler_consumption(self, pv_data):
if len(pv_data["boiler"]) > 0 and pv_data["boiler"]["p"] is not None:
# Spotreba bojleru
if (
len(pv_data["boiler"]) > 0
and pv_data["boiler"]["p"] is not None
and pv_data["boiler"]["p"] > 0
self._sensor_type == "boiler_current_w"
and pv_data["boiler"]["p"] > 0
and (
pv_data["ac_in"]["aci_wr"]
+ pv_data["ac_in"]["aci_ws"]
+ pv_data["ac_in"]["aci_wt"]
)
< 0
):
boiler_p = pv_data["boiler"]["p"]
return float(
# Výkon FVE
(pv_data["dc_in"]["fv_p1"] + pv_data["dc_in"]["fv_p2"])
-
# Spotřeba bojleru
boiler_p
-
# Spotřeba zátěž
pv_data["ac_out"]["aco_p"]
+
# Odběr ze sítě
(
return float(
pv_data["boiler"]["p"]
+ (
pv_data["ac_in"]["aci_wr"]
+ pv_data["ac_in"]["aci_ws"]
+ pv_data["ac_in"]["aci_wt"]
)
)
+
# Nabíjení/vybíjení baterie
(pv_data["batt"]["bat_i"] * pv_data["batt"]["bat_v"] * -1)
)

return None
elif self._sensor_type == "boiler_current_w":
return float(pv_data["boiler"]["p"])
else:
return None

async def async_update(self):
# Request the coordinator to fetch new data and update the entity's state
Expand Down
76 changes: 48 additions & 28 deletions custom_components/oig_cloud/oig_cloud_data_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,60 @@ def state(self):

# special cases
if self._sensor_type == "box_prms_mode":
if node_value == 0:
return "Home 1"
elif node_value == 1:
return "Home 2"
elif node_value == 2:
return "Home 3"
elif node_value == 3:
return "Home UPS"
return _LANGS["unknown"][language]
return self._get_mode_name(node_value, language)

if self._sensor_type == "invertor_prms_to_grid":
grid_enabled = int(pv_data["box_prms"]["crcte"])
to_grid = int(node_value)
max_grid_feed = int(pv_data["invertor_prm1"]["p_max_feed_grid"])
return self._grid_mode(pv_data, node_value, language)

if bool(pv_data["queen"]):
vypnuto = 0 == to_grid and 0 == max_grid_feed
zapnuto = 1 == to_grid
limited = 0 == to_grid and 0 < max_grid_feed
else:
vypnuto = 0 == grid_enabled and 0 == to_grid
zapnuto = 1 == grid_enabled and 1 == to_grid and 10000 == max_grid_feed
limited = 1 == grid_enabled and 1 == to_grid and 9999 >= max_grid_feed

if vypnuto:
return GridMode.OFF.value
elif limited:
return GridMode.LIMITED.value
elif zapnuto:
return GridMode.ON.value
return _LANGS["changing"][language]
try:
return float(node_value)
except ValueError:
return node_value
except KeyError:
return None

def _get_mode_name(self, node_value, language):
if node_value == 0:
return "Home 1"
elif node_value == 1:
return "Home 2"
elif node_value == 2:
return "Home 3"
elif node_value == 3:
return "Home UPS"
return _LANGS["unknown"][language]

def _grid_mode(self, pv_data, node_value, language):
grid_enabled = int(pv_data["box_prms"]["crcte"])
to_grid = int(node_value)
max_grid_feed = int(pv_data["invertor_prm1"]["p_max_feed_grid"])

if bool(pv_data["queen"]):
return self._grid_mode_queen(grid_enabled, to_grid, max_grid_feed, language)
return self._grid_mode_king(grid_enabled, to_grid, max_grid_feed, language)

def _grid_mode_queen(self, grid_enabled, to_grid, max_grid_feed, language):
vypnuto = 0 == to_grid and 0 == max_grid_feed
zapnuto = 1 == to_grid
limited = 0 == to_grid and 0 < max_grid_feed

if vypnuto:
return GridMode.OFF.value
elif limited:
return GridMode.LIMITED.value
elif zapnuto:
return GridMode.ON.value
return _LANGS["changing"][language]

def _grid_mode_king(self, grid_enabled, to_grid, max_grid_feed, language):
vypnuto = 0 == grid_enabled and 0 == to_grid
zapnuto = 1 == grid_enabled and 1 == to_grid and 10000 == max_grid_feed
limited = 1 == grid_enabled and 1 == to_grid and 9999 >= max_grid_feed

if vypnuto:
return GridMode.OFF.value
elif limited:
return GridMode.LIMITED.value
elif zapnuto:
return GridMode.ON.value
return _LANGS["changing"][language]
Loading