Structure package and fix ApiError
This commit is contained in:
parent
51486518b4
commit
a009564b74
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
|
||||||
|
*.egg-info/
|
4
pyproject.toml
Normal file
4
pyproject.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
13
setup.cfg
Normal file
13
setup.cfg
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[metadata]
|
||||||
|
name = yamaha2mqtt
|
||||||
|
version = 0.0.1
|
||||||
|
|
||||||
|
[options]
|
||||||
|
package_dir =
|
||||||
|
=src
|
||||||
|
packages = find_namespace:
|
||||||
|
# install_requires =
|
||||||
|
|
||||||
|
[options.packages.find]
|
||||||
|
where = src
|
||||||
|
|
@ -16,7 +16,8 @@ def main(\
|
|||||||
mqtt_port: int = typer.Option(... , envvar="YAMAHA_MQTT_PORT"),\
|
mqtt_port: int = typer.Option(... , envvar="YAMAHA_MQTT_PORT"),\
|
||||||
yamaha_host: str = typer.Option(... , envvar="YAMAHA_HOST"),\
|
yamaha_host: str = typer.Option(... , envvar="YAMAHA_HOST"),\
|
||||||
senarios_file: Optional[Path] = typer.Option(None, exists=True,
|
senarios_file: Optional[Path] = typer.Option(None, exists=True,
|
||||||
file_okay=True, dir_okay=False, readable=True, resolve_path=True)\
|
file_okay=True, dir_okay=False, readable=True, resolve_path=True,
|
||||||
|
envvar="YAMAHA_SENARIOS")\
|
||||||
):
|
):
|
||||||
|
|
||||||
if senarios_file:
|
if senarios_file:
|
@ -25,7 +25,6 @@ class Yamaha:
|
|||||||
self._client.subscribe_callback('yamaha/cmnd/senario', self.handle_senario)
|
self._client.subscribe_callback('yamaha/cmnd/senario', self.handle_senario)
|
||||||
self._client.subscribe_callback('yamaha/cmnd/senario/available', self.handle_senario_available)
|
self._client.subscribe_callback('yamaha/cmnd/senario/available', self.handle_senario_available)
|
||||||
self._client.subscribe_callback('yamaha/cmnd/volume', self.handle_volume)
|
self._client.subscribe_callback('yamaha/cmnd/volume', self.handle_volume)
|
||||||
self._client.subscribe_callback('yamaha/cmnd/volume/params', self.handle_volume_params)
|
|
||||||
self._client.subscribe_callback('yamaha/cmnd/power', self.handle_power)
|
self._client.subscribe_callback('yamaha/cmnd/power', self.handle_power)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -47,7 +46,7 @@ class Yamaha:
|
|||||||
raise ConnectionTimeoutError()
|
raise ConnectionTimeoutError()
|
||||||
r_json = r.json()
|
r_json = r.json()
|
||||||
if r_json['response_code'] != 0:
|
if r_json['response_code'] != 0:
|
||||||
raise ApiResponse(r.url, r_json['response_code'])
|
raise ApiError(r.url, r_json['response_code'])
|
||||||
return r_json
|
return r_json
|
||||||
|
|
||||||
def search_senario(self, name: str):
|
def search_senario(self, name: str):
|
||||||
@ -78,13 +77,6 @@ class Yamaha:
|
|||||||
self._client.publish('yamaha/stat/senario/available',
|
self._client.publish('yamaha/stat/senario/available',
|
||||||
json.dumps([s.__name__.lower() for s in self.available_senarios]))
|
json.dumps([s.__name__.lower() for s in self.available_senarios]))
|
||||||
|
|
||||||
def handle_volume_params(self, client, userdata, msg):
|
|
||||||
r = self.request(Zone().get_status('main'))
|
|
||||||
msg = {
|
|
||||||
'maximum': r['max_volume']
|
|
||||||
}
|
|
||||||
self._client.publish('yamaha/stat/volume/params', json.dumps(msg))
|
|
||||||
|
|
||||||
def handle_volume(self, client, userdata, msg):
|
def handle_volume(self, client, userdata, msg):
|
||||||
param =msg.payload.decode().lower()
|
param =msg.payload.decode().lower()
|
||||||
|
|
||||||
@ -96,7 +88,12 @@ class Yamaha:
|
|||||||
self.request(Zone().set_volume('main', param, ''))
|
self.request(Zone().set_volume('main', param, ''))
|
||||||
|
|
||||||
r = self.request(Zone().get_status('main'))
|
r = self.request(Zone().get_status('main'))
|
||||||
self._client.publish('yamaha/stat/volume', r['volume'])
|
msg = {
|
||||||
|
'volume_max': r['max_volume'],
|
||||||
|
'volume': r['volume'],
|
||||||
|
}
|
||||||
|
|
||||||
|
self._client.publish('yamaha/stat/volume', json.dumps(msg))
|
||||||
|
|
||||||
def handle_power(self, client, userdata, msg):
|
def handle_power(self, client, userdata, msg):
|
||||||
param =msg.payload.decode().lower()
|
param =msg.payload.decode().lower()
|
||||||
@ -110,3 +107,4 @@ class Yamaha:
|
|||||||
state = r['power']
|
state = r['power']
|
||||||
state = 'off' if state == 'standby' else state
|
state = 'off' if state == 'standby' else state
|
||||||
self._client.publish('yamaha/stat/power', state)
|
self._client.publish('yamaha/stat/power', state)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user