-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4b4fc54
Showing
21 changed files
with
3,038 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
We as members, contributors, and leaders pledge to make participation in our | ||
community a harassment-free experience for everyone, regardless of age, body | ||
size, visible or invisible disability, ethnicity, sex characteristics, gender | ||
identity and expression, level of experience, education, socio-economic status, | ||
nationality, personal appearance, race, religion, or sexual identity | ||
and orientation. | ||
|
||
We pledge to act and interact in ways that contribute to an open, welcoming, | ||
diverse, inclusive, and healthy community. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to a positive environment for our | ||
community include: | ||
|
||
* Demonstrating empathy and kindness toward other people | ||
* Being respectful of differing opinions, viewpoints, and experiences | ||
* Giving and gracefully accepting constructive feedback | ||
* Accepting responsibility and apologizing to those affected by our mistakes, | ||
and learning from the experience | ||
* Focusing on what is best not just for us as individuals, but for the | ||
overall community | ||
|
||
Examples of unacceptable behavior include: | ||
|
||
* The use of sexualized language or imagery, and sexual attention or | ||
advances of any kind | ||
* Trolling, insulting or derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or email | ||
address, without their explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Enforcement Responsibilities | ||
|
||
Community leaders are responsible for clarifying and enforcing our standards of | ||
acceptable behavior and will take appropriate and fair corrective action in | ||
response to any behavior that they deem inappropriate, threatening, offensive, | ||
or harmful. | ||
|
||
Community leaders have the right and responsibility to remove, edit, or reject | ||
comments, commits, code, wiki edits, issues, and other contributions that are | ||
not aligned to this Code of Conduct, and will communicate reasons for moderation | ||
decisions when appropriate. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies within all community spaces, and also applies when | ||
an individual is officially representing the community in public spaces. | ||
Examples of representing our community include using an official e-mail address, | ||
posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported to the community leaders responsible for enforcement at | ||
GitHub. | ||
All complaints will be reviewed and investigated promptly and fairly. | ||
|
||
All community leaders are obligated to respect the privacy and security of the | ||
reporter of any incident. | ||
|
||
## Enforcement Guidelines | ||
|
||
Community leaders will follow these Community Impact Guidelines in determining | ||
the consequences for any action they deem in violation of this Code of Conduct: | ||
|
||
### 1. Correction | ||
|
||
**Community Impact**: Use of inappropriate language or other behavior deemed | ||
unprofessional or unwelcome in the community. | ||
|
||
**Consequence**: A private, written warning from community leaders, providing | ||
clarity around the nature of the violation and an explanation of why the | ||
behavior was inappropriate. A public apology may be requested. | ||
|
||
### 2. Warning | ||
|
||
**Community Impact**: A violation through a single incident or series | ||
of actions. | ||
|
||
**Consequence**: A warning with consequences for continued behavior. No | ||
interaction with the people involved, including unsolicited interaction with | ||
those enforcing the Code of Conduct, for a specified period of time. This | ||
includes avoiding interactions in community spaces as well as external channels | ||
like social media. Violating these terms may lead to a temporary or | ||
permanent ban. | ||
|
||
### 3. Temporary Ban | ||
|
||
**Community Impact**: A serious violation of community standards, including | ||
sustained inappropriate behavior. | ||
|
||
**Consequence**: A temporary ban from any sort of interaction or public | ||
communication with the community for a specified period of time. No public or | ||
private interaction with the people involved, including unsolicited interaction | ||
with those enforcing the Code of Conduct, is allowed during this period. | ||
Violating these terms may lead to a permanent ban. | ||
|
||
### 4. Permanent Ban | ||
|
||
**Community Impact**: Demonstrating a pattern of violation of community | ||
standards, including sustained inappropriate behavior, harassment of an | ||
individual, or aggression toward or disparagement of classes of individuals. | ||
|
||
**Consequence**: A permanent ban from any sort of public interaction within | ||
the community. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], | ||
version 2.0, available at | ||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. | ||
|
||
Community Impact Guidelines were inspired by [Mozilla's code of conduct | ||
enforcement ladder](https://github.com/mozilla/diversity). | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
||
For answers to common questions about this code of conduct, see the FAQ at | ||
https://www.contributor-covenant.org/faq. Translations are available at | ||
https://www.contributor-covenant.org/translations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Chirp - ChirpStack LoraWan Integration | ||
|
||
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) (https://github.com/modrisb/pijups/releases) | ||
|
||
|
||
Chirp as [Home Assistant](https://home-assistant.io) integration component glues together HA MQTT and ChirStack LoraWan server. LoraWan devices information is retrived from ChirpStack gRPC api server and exposed to HA MQTT integration discovery service. Data transferred by/ty LoraWan devices are retained on MQTT server to support HA/integration restart. Detailed configuration information needed for HA is stored as ChirpStack codec extension. | ||
|
||
## Sensors supported | ||
* Chirp does not limit devices by type/features, but is limited by codec extension that need to be prepared for each device separately. | ||
|
||
## Prerequisite | ||
HA MQTT integration with MQTT server must be available to Chirp as to Chirpstack server also.<br> | ||
|
||
## Manual installation | ||
1. Inside the `custom_components` directory, create a new folder called `chirp`. | ||
2. Download all files from the `custom_components/chirp/` repository to this directory `custom_components/chirp`. | ||
3. Install integration from Home Assistant Settings/Devices & Services/Add Integration and continue with UI configuration. ChirpStack server credentials required, including API key used for connection authentication. On HA side MQTT server credentials and MQTT discovery details needed. | ||
|
||
HACS might be used for installation too - check repository 'Chirp'. | ||
|
||
## Devices Configuration | ||
Chirp uses ChirpStack device template information for device type details and device specifics (device enabled, device battery details), HA integration details are encoded in ChirpStack device template javascript codec. Codec must be appended by function similar to: | ||
|
||
function getHaDeviceInfo() { | ||
return { | ||
device: { | ||
manufacturer: "Milesight IoT Co., Ltd", | ||
model: "WS52x" | ||
}, | ||
entities: { | ||
current:{ | ||
entity_conf: { | ||
value_template: "{{ (value_json.object.current | float) / 1000 }}", | ||
entity_category: "diagnostic", | ||
state_class: "measurement", | ||
device_class: "current", | ||
unit_of_measurement: "A" | ||
} | ||
}, | ||
factor:{ | ||
entity_conf: { | ||
value_template: "{{ (value_json.object.factor | float) / 100 }}", | ||
entity_category: "diagnostic", | ||
state_class: "measurement", | ||
device_class: "power_factor", | ||
} | ||
}, | ||
power:{ | ||
entity_conf: { | ||
value_template: "{{ value_json.object.power | float }}", | ||
entity_category: "diagnostic", | ||
state_class: "measurement", | ||
device_class: "power", | ||
unit_of_measurement: "W" | ||
} | ||
}, | ||
voltage:{ | ||
entity_conf: { | ||
value_template: "{{ value_json.object.voltage | float }}", | ||
entity_category: "diagnostic", | ||
state_class: "measurement", | ||
device_class: "voltage", | ||
unit_of_measurement: "V" | ||
} | ||
}, | ||
outage:{ | ||
integration: "binary_sensor", | ||
entity_conf: { | ||
entity_category: "diagnostic", | ||
device_class: "power" | ||
} | ||
}, | ||
power_sum:{ | ||
entity_conf: { | ||
value_template: "{{ (value_json.object.power_sum | float) / 1000 }}", | ||
state_class: "total_increasing", | ||
device_class: "energy", | ||
unit_of_measurement: "kWh" | ||
} | ||
}, | ||
state:{ | ||
integration: "switch", | ||
entity_conf: { | ||
value_template: "{{ value_json.object.state }}", | ||
command_topic: "{command_topic}", | ||
state_on: "open", | ||
state_off: "close", | ||
payload_off: '{{"dev_eui":"{dev_eui}","confirmed":true,"fPort":85,"data":"CAAA/w=="}}', | ||
payload_on: '{{"dev_eui":"{dev_eui}","confirmed":true,"fPort":85,"data":"CAEA/w=="}}' | ||
} | ||
}, | ||
rssi:{ | ||
entity_conf: { | ||
value_template: "{{ value_json.rxInfo[-1].rssi | int }}", | ||
entity_category: "diagnostic", | ||
device_class: "signal_strength", | ||
unit_of_measurement: "dBm", | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
Device information is used only for visualization, entities describe sensor details - how they are integrated into HA. value_template defines sensor value extraction rules from device payload and possible conversions (like converting to int/float and applying needed factors). Integration type is needed for MQTT to implement proper processing together with device class definition. | ||
|
||
## Credits | ||
[ChirpStack](https://chirpstack.io/) : open-source LoRaWAN Network Server<br> | ||
[Home Assistant](https://github.com/home-assistant) : Home Assistant open-source powerful domotic plateform with MQTT integratio.<br> | ||
[HACS](https://hacs.xyz/) : Home Assistant Community Store gives you a powerful UI to handle downloads of all your custom needs.<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""The Chirpstack LoRaWan integration - setup.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import Platform | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .const import CONF_APPLICATION_ID, DOMAIN, GRPCLIENT, MQTTCLIENT | ||
from .grpc import ChirpGrpc | ||
from .mqtt import ChirpToHA | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
# List of platforms to support. There should be a matching .py file for each, | ||
# eg <cover.py> and <sensor.py> | ||
PLATFORMS: list[Platform] = [Platform.SENSOR] | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Set up PiJups from a config entry.""" | ||
# Store an instance of the "connecting" class that does the work of speaking | ||
# with your actual devices. | ||
_LOGGER.debug( | ||
"async_setup_entry application id %s", entry.data.get(CONF_APPLICATION_ID) | ||
) | ||
hass.data.setdefault(DOMAIN, {}) | ||
|
||
grpc_client = ChirpGrpc(hass, entry) | ||
mqtt_client = ChirpToHA(hass, entry, grpc_client) | ||
|
||
hass.data[DOMAIN][entry.entry_id] = { | ||
GRPCLIENT: grpc_client, | ||
MQTTCLIENT: mqtt_client, | ||
} | ||
|
||
mqtt_client.start_bridge() | ||
|
||
# This creates each HA object for each platform your device requires. | ||
# It's done by calling the `async_setup_entry` function in each platform module. | ||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
_LOGGER.debug("async_setup_entry completed") | ||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
# This is called when an entry/configured device is to be removed. The class | ||
# needs to unload itself, and remove callbacks. See the classes for further | ||
# details | ||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
if unload_ok: | ||
hass.data[DOMAIN][entry.entry_id][GRPCLIENT].close() | ||
hass.data[DOMAIN][entry.entry_id][MQTTCLIENT].close() | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
_LOGGER.debug( | ||
"async_unload_entry completed, platform unload return code %s", unload_ok | ||
) | ||
return unload_ok |
Oops, something went wrong.