Skip to content

Commit

Permalink
Merge pull request #19 from BrewBlox/develop
Browse files Browse the repository at this point in the history
Edge release
  • Loading branch information
steersbob authored May 30, 2023
2 parents e2c442f + e6fdfe8 commit f91b968
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 6 deletions.
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"editorconfig.editorconfig",
"littlefoxteam.vscode-python-test-adapter",
"ms-python.python",
"ms-python.vscode-pylance"
"ms-python.vscode-pylance",
"ms-python.autopep8"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
}
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance"
"python.languageServer": "Pylance",
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none",
"python.analysis.diagnosticMode": "workspace"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We'll probably get around to extending this service, but it will take some time.

## Getting started

First, enable MQTT discovery in HA: <https://www.home-assistant.io/docs/mqtt/discovery/>.
First, enable MQTT discovery in HA: <https://www.home-assistant.io/integrations/mqtt>.

Then, add the brewblox-hass service to your docker-compose.yml file:

Expand Down
29 changes: 29 additions & 0 deletions brewblox_hass/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
'TempSensorOneWire',
'TempSensorCombi',
'TempSensorMock',
'TempSensorExternal',
]
SETPOINT_TYPES = [
'SetpointSensorPair',
]
PROFILE_TYPES = [
'SetpointProfile',
]
HANDLED_TYPES = [
*SENSOR_TYPES,
*SETPOINT_TYPES,
*PROFILE_TYPES,
]
UNITS = {
'degC': '°C',
Expand All @@ -38,6 +43,10 @@ def fallback(data: dict, k1: str, k2: str):
return data.get(k1, data.get(k2))


def binary_sensor_state(value: bool):
return 'ON' if value else 'OFF'


class Relay(features.ServiceFeature):

def __init__(self, app: web.Application, publisher: mqtt.EventHandler):
Expand Down Expand Up @@ -122,6 +131,26 @@ async def handle_spark_state(self, message: dict):
)
self.known.add(full)

if block['type'] in PROFILE_TYPES:
qty = block['data']['setting']
value = qty['value']

published_state[sanitized] = binary_sensor_state(value is not None)

if full not in self.known:
LOGGER.info(f'publishing new profile state: {id}')
await self.publisher.publish(
topic=f'homeassistant/binary_sensor/{full}/config',
message=json.dumps({
'device_class': 'running',
'name': f'{id} ({service})',
'state_topic': state_topic,
'value_template': '{{ value_json.' + sanitized + ' }}',
}),
retain=True,
)
self.known.add(full)

if published_state:
await self.publisher.publish(
topic=state_topic,
Expand Down
133 changes: 132 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = ">=3.9,<4"
brewblox-service = "^2.1.0"
cryptography = "40.0.1"

[tool.poetry.dev-dependencies]
pytest-cov = "*"
Expand All @@ -21,5 +22,5 @@ flake8-quotes = "*"
aresponses = "*"

[build-system]
requires = ["poetry>=0.12"]
requires = ["poetry>=0.12", "cryptography==40.0.1"]
build-backend = "poetry.masonry.api"

0 comments on commit f91b968

Please sign in to comment.