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

Add pre-commit and black #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cbpi/extension/ui
node_modules
.DS_STORE
.vscode
.DS_Store
.DS_Store
.vscode/
config/*
logs/
logs/
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- repo: https://github.com/ambv/black
rev: 21.5b0
hooks:
- id: black
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ COPY . .
EXPOSE 8080

CMD [ "cbpi" ]


2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
recursive-include cbpi/config *
recursive-include cbpi/extension *
recursive-include cbpi/static *
recursive-include cbpi/static *
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# CraftBeerPi

You will finde the documentation here: https://craftbeerpi.gitbook.io/craftbeerpi4/

2 changes: 1 addition & 1 deletion cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.0.0.29"
__version__ = "4.0.0.29"
38 changes: 20 additions & 18 deletions cbpi/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
__all__ = ["CBPiActor",
"CBPiExtension",
"Property",
"PropertyType",
"on_event",
"on_startup",
"request_mapping",
"action",
"parameters",
"background_task",
"CBPiKettleLogic",
"CBPiException",
"KettleException",
"SensorException",
"ActorException",
"CBPiSensor",
"CBPiStep"]
__all__ = [
"CBPiActor",
"CBPiExtension",
"Property",
"PropertyType",
"on_event",
"on_startup",
"request_mapping",
"action",
"parameters",
"background_task",
"CBPiKettleLogic",
"CBPiException",
"KettleException",
"SensorException",
"ActorException",
"CBPiSensor",
"CBPiStep",
]

from cbpi.api.actor import *
from cbpi.api.sensor import *
Expand All @@ -23,4 +25,4 @@
from cbpi.api.decorator import *
from cbpi.api.kettle_logic import *
from cbpi.api.step import *
from cbpi.api.exceptions import *
from cbpi.api.exceptions import *
42 changes: 19 additions & 23 deletions cbpi/api/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@


class CBPiActor(metaclass=ABCMeta):

def __init__(self, cbpi, id, props):
self.cbpi = cbpi
self.id = id
self.props = props
self.logger = logging.getLogger(__file__)
self.data_logger = None
self.state = False
self.state = False
self.running = False

def init(self):
pass

def log_data(self, value):
self.cbpi.log.log_data(self.id, value)

def get_state(self):
return dict(state=self.state)

Expand All @@ -44,7 +43,7 @@ async def on_stop(self):

async def run(self):
pass

async def _run(self):

try:
Expand All @@ -55,37 +54,34 @@ async def _run(self):
finally:
await self.on_stop()



def get_static_config_value(self,name,default):
def get_static_config_value(self, name, default):
return self.cbpi.static_config.get(name, default)

def get_config_value(self,name,default):
def get_config_value(self, name, default):
return self.cbpi.config.get(name, default=default)

async def set_config_value(self,name,value):
return await self.cbpi.config.set(name,value)
async def set_config_value(self, name, value):
return await self.cbpi.config.set(name, value)

async def add_config_value(self, name, value, type: ConfigType, description, options=None):
async def add_config_value(
self, name, value, type: ConfigType, description, options=None
):
await self.cbpi.add(name, value, type, description, options=None)

async def on(self, power):
'''
Code to switch the actor on. Power is provided as integer value
:param power: power value between 0 and 100
"""
Code to switch the actor on. Power is provided as integer value

:param power: power value between 0 and 100
:return: None
'''
"""
pass

async def off(self):

'''
"""
Code to switch the actor off

:return: None
'''
pass



:return: None
"""
pass
39 changes: 19 additions & 20 deletions cbpi/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,56 @@


class CBPiBase(metaclass=ABCMeta):

def get_static_config_value(self,name,default):
def get_static_config_value(self, name, default):
return self.cbpi.static_config.get(name, default)

def get_config_value(self,name,default):
def get_config_value(self, name, default):
return self.cbpi.config.get(name, default=default)

async def set_config_value(self,name,value):
return await self.cbpi.config.set(name,value)
async def set_config_value(self, name, value):
return await self.cbpi.config.set(name, value)

async def add_config_value(self, name, value, type: ConfigType, description, options=None):
async def add_config_value(
self, name, value, type: ConfigType, description, options=None
):
await self.cbpi.add(name, value, type, description, options=None)

def get_kettle(self,id):
def get_kettle(self, id):
return self.cbpi.kettle.find_by_id(id)

def get_kettle_target_temp(self,id):
def get_kettle_target_temp(self, id):
return self.cbpi.kettle.find_by_id(id).target_temp

async def set_target_temp(self,id, temp):
async def set_target_temp(self, id, temp):
await self.cbpi.kettle.set_target_temp(id, temp)

def get_sensor(self,id):
def get_sensor(self, id):
return self.cbpi.sensor.find_by_id(id)
def get_sensor_value(self,id):

def get_sensor_value(self, id):

return self.cbpi.sensor.get_sensor_value(id)

def get_actor(self,id):
def get_actor(self, id):
return self.cbpi.actor.find_by_id(id)

def get_actor_state(self,id):
def get_actor_state(self, id):
try:
actor = self.cbpi.actor.find_by_id(id)
return actor.get("instance").get_state()
except:
logging.error("Faild to read actor state in step - actor {}".format(id))
return None

async def actor_on(self,id):
async def actor_on(self, id):

try:
await self.cbpi.actor.on(id)
except Exception as e:
pass

async def actor_off(self,id):
async def actor_off(self, id):
try:
await self.cbpi.actor.off(id)
except Exception as e:
pass


3 changes: 1 addition & 2 deletions cbpi/api/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from enum import Enum


class ConfigType(Enum):
STRING = "string"
NUMBER = "number"
SELECT = "select"
KETTLE = "kettle"
ACTOR = "actor"
SENSOR = "sensor"


Loading