Skip to content

Commit 4b4fc54

Browse files
committed
Initial
0 parents  commit 4b4fc54

21 files changed

+3038
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, religion, or sexual identity
10+
and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the
26+
overall community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or
31+
advances of any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email
35+
address, without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official e-mail address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
GitHub.
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series
86+
of actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or
93+
permanent ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within
113+
the community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.0, available at
119+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120+
121+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122+
enforcement ladder](https://github.com/mozilla/diversity).
123+
124+
[homepage]: https://www.contributor-covenant.org
125+
126+
For answers to common questions about this code of conduct, see the FAQ at
127+
https://www.contributor-covenant.org/faq. Translations are available at
128+
https://www.contributor-covenant.org/translations.

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Chirp - ChirpStack LoraWan Integration
2+
3+
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/custom-components/hacs) (https://github.com/modrisb/pijups/releases)
4+
5+
6+
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.
7+
8+
## Sensors supported
9+
* Chirp does not limit devices by type/features, but is limited by codec extension that need to be prepared for each device separately.
10+
11+
## Prerequisite
12+
HA MQTT integration with MQTT server must be available to Chirp as to Chirpstack server also.<br>
13+
14+
## Manual installation
15+
1. Inside the `custom_components` directory, create a new folder called `chirp`.
16+
2. Download all files from the `custom_components/chirp/` repository to this directory `custom_components/chirp`.
17+
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.
18+
19+
HACS might be used for installation too - check repository 'Chirp'.
20+
21+
## Devices Configuration
22+
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:
23+
24+
function getHaDeviceInfo() {
25+
return {
26+
device: {
27+
manufacturer: "Milesight IoT Co., Ltd",
28+
model: "WS52x"
29+
},
30+
entities: {
31+
current:{
32+
entity_conf: {
33+
value_template: "{{ (value_json.object.current | float) / 1000 }}",
34+
entity_category: "diagnostic",
35+
state_class: "measurement",
36+
device_class: "current",
37+
unit_of_measurement: "A"
38+
}
39+
},
40+
factor:{
41+
entity_conf: {
42+
value_template: "{{ (value_json.object.factor | float) / 100 }}",
43+
entity_category: "diagnostic",
44+
state_class: "measurement",
45+
device_class: "power_factor",
46+
}
47+
},
48+
power:{
49+
entity_conf: {
50+
value_template: "{{ value_json.object.power | float }}",
51+
entity_category: "diagnostic",
52+
state_class: "measurement",
53+
device_class: "power",
54+
unit_of_measurement: "W"
55+
}
56+
},
57+
voltage:{
58+
entity_conf: {
59+
value_template: "{{ value_json.object.voltage | float }}",
60+
entity_category: "diagnostic",
61+
state_class: "measurement",
62+
device_class: "voltage",
63+
unit_of_measurement: "V"
64+
}
65+
},
66+
outage:{
67+
integration: "binary_sensor",
68+
entity_conf: {
69+
entity_category: "diagnostic",
70+
device_class: "power"
71+
}
72+
},
73+
power_sum:{
74+
entity_conf: {
75+
value_template: "{{ (value_json.object.power_sum | float) / 1000 }}",
76+
state_class: "total_increasing",
77+
device_class: "energy",
78+
unit_of_measurement: "kWh"
79+
}
80+
},
81+
state:{
82+
integration: "switch",
83+
entity_conf: {
84+
value_template: "{{ value_json.object.state }}",
85+
command_topic: "{command_topic}",
86+
state_on: "open",
87+
state_off: "close",
88+
payload_off: '{{"dev_eui":"{dev_eui}","confirmed":true,"fPort":85,"data":"CAAA/w=="}}',
89+
payload_on: '{{"dev_eui":"{dev_eui}","confirmed":true,"fPort":85,"data":"CAEA/w=="}}'
90+
}
91+
},
92+
rssi:{
93+
entity_conf: {
94+
value_template: "{{ value_json.rxInfo[-1].rssi | int }}",
95+
entity_category: "diagnostic",
96+
device_class: "signal_strength",
97+
unit_of_measurement: "dBm",
98+
}
99+
}
100+
}
101+
};
102+
}
103+
104+
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.
105+
106+
## Credits
107+
[ChirpStack](https://chirpstack.io/) : open-source LoRaWAN Network Server<br>
108+
[Home Assistant](https://github.com/home-assistant) : Home Assistant open-source powerful domotic plateform with MQTT integratio.<br>
109+
[HACS](https://hacs.xyz/) : Home Assistant Community Store gives you a powerful UI to handle downloads of all your custom needs.<br>

custom_components/chirp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__/

custom_components/chirp/__init__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""The Chirpstack LoRaWan integration - setup."""
2+
from __future__ import annotations
3+
4+
import logging
5+
6+
from homeassistant.config_entries import ConfigEntry
7+
from homeassistant.const import Platform
8+
from homeassistant.core import HomeAssistant
9+
10+
from .const import CONF_APPLICATION_ID, DOMAIN, GRPCLIENT, MQTTCLIENT
11+
from .grpc import ChirpGrpc
12+
from .mqtt import ChirpToHA
13+
14+
_LOGGER = logging.getLogger(__name__)
15+
16+
# List of platforms to support. There should be a matching .py file for each,
17+
# eg <cover.py> and <sensor.py>
18+
PLATFORMS: list[Platform] = [Platform.SENSOR]
19+
20+
21+
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
22+
"""Set up PiJups from a config entry."""
23+
# Store an instance of the "connecting" class that does the work of speaking
24+
# with your actual devices.
25+
_LOGGER.debug(
26+
"async_setup_entry application id %s", entry.data.get(CONF_APPLICATION_ID)
27+
)
28+
hass.data.setdefault(DOMAIN, {})
29+
30+
grpc_client = ChirpGrpc(hass, entry)
31+
mqtt_client = ChirpToHA(hass, entry, grpc_client)
32+
33+
hass.data[DOMAIN][entry.entry_id] = {
34+
GRPCLIENT: grpc_client,
35+
MQTTCLIENT: mqtt_client,
36+
}
37+
38+
mqtt_client.start_bridge()
39+
40+
# This creates each HA object for each platform your device requires.
41+
# It's done by calling the `async_setup_entry` function in each platform module.
42+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
43+
_LOGGER.debug("async_setup_entry completed")
44+
return True
45+
46+
47+
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
48+
"""Unload a config entry."""
49+
# This is called when an entry/configured device is to be removed. The class
50+
# needs to unload itself, and remove callbacks. See the classes for further
51+
# details
52+
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
53+
if unload_ok:
54+
hass.data[DOMAIN][entry.entry_id][GRPCLIENT].close()
55+
hass.data[DOMAIN][entry.entry_id][MQTTCLIENT].close()
56+
hass.data[DOMAIN].pop(entry.entry_id)
57+
_LOGGER.debug(
58+
"async_unload_entry completed, platform unload return code %s", unload_ok
59+
)
60+
return unload_ok

0 commit comments

Comments
 (0)