Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build and Release

on:
push:
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install build tools
run: pip install build

- name: Build wheel
run: python -m build --wheel

- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: dist/*.whl
generate_release_notes: true
15 changes: 11 additions & 4 deletions pycec/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def main():

transports = set()
loop = asyncio.get_event_loop()
network = HDMINetwork(CecAdapter("pyCEC", activate_source=False),
adapter_path = config['DEFAULT']['adapter'] if config['DEFAULT']['adapter'] else None
network = HDMINetwork(CecAdapter("pyCEC", activate_source=False,
adapter_path=adapter_path),
loop=loop)

class CECServerProtocol(asyncio.Protocol):
Expand Down Expand Up @@ -109,16 +111,21 @@ def configure():
default=DEFAULT_PORT,
help=("Port to bind to. Default is '%s'."
% DEFAULT_PORT))
parser.add_option("-a", "--adapter", dest="adapter", action="store",
type="string", default=None,
help="CEC adapter path to use (e.g., '/dev/cec0'). "
"If not specified, uses first adapter found.")
parser.add_option("-v", "--verbose", dest="verbose", action="count",
default=0, help="Increase verbosity.")
parser.add_option("-q", "--quiet", dest="quiet", action="count",
default=0, help="Decrease verbosity.")
(options, args) = parser.parse_args()
script_dir = os.path.dirname(os.path.realpath(__file__))
config = configparser.ConfigParser()
config['DEFAULT'] = {'host': options.host, 'port': options.port,
'logLevel': logging.INFO + (
(options.quiet - options.verbose) * 10)}
config['DEFAULT'] = {'host': options.host, 'port': str(options.port),
'adapter': options.adapter or '',
'logLevel': str(logging.INFO + (
(options.quiet - options.verbose) * 10))}
paths = ['/etc/pycec.conf', script_dir + '/pycec.conf']
if 'HOME' in os.environ:
paths.append(os.environ['HOME'] + '/.pycec')
Expand Down
28 changes: 18 additions & 10 deletions pycec/cec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
class CecAdapter(AbstractCecAdapter):
def __init__(self, name: str = None, monitor_only: bool = None,
activate_source: bool = None,
device_type=ADDR_RECORDINGDEVICE1):
device_type=ADDR_RECORDINGDEVICE1, adapter_path: str = None):
super().__init__()
self._adapter = None
self._io_executor = ThreadPoolExecutor(1)
self._adapter_path = adapter_path
import cec
self._cecconfig = cec.libcec_configuration()
if monitor_only is not None:
Expand Down Expand Up @@ -68,15 +69,22 @@ def _init(self, callback: callable = None):
adapter = cec.ICECAdapter.Create(self._cecconfig)
_LOGGER.debug("Created adapter")
a = None
adapters = adapter.DetectAdapters()
for a in adapters:
_LOGGER.info("found a CEC adapter:")
_LOGGER.info("port: " + a.strComName)
_LOGGER.info("vendor: " + (
VENDORS[a.iVendorId] if a.iVendorId in VENDORS else hex(
a.iVendorId)))
_LOGGER.info("product: " + hex(a.iProductId))
a = a.strComName
if self._adapter_path:
a = self._adapter_path
_LOGGER.info("Using specified adapter: %s", a)
else:
first_adapter = None
adapters = adapter.DetectAdapters()
for adapter_info in adapters:
_LOGGER.info("found a CEC adapter:")
_LOGGER.info("port: " + adapter_info.strComName)
_LOGGER.info("vendor: " + (
VENDORS[adapter_info.iVendorId] if adapter_info.iVendorId in VENDORS else hex(
adapter_info.iVendorId)))
_LOGGER.info("product: " + hex(adapter_info.iProductId))
if first_adapter is None:
first_adapter = adapter_info.strComName
a = first_adapter
if a is None:
_LOGGER.warning("No adapters found")
else:
Expand Down
39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
[project]
name = "pycec"
version = "0.6.1"
description = "Provide HDMI CEC devices as objects, especially for use with Home Assistant"
readme = "README.md"
requires-python = ">=3.9"
license = "MIT"
keywords = ["cec", "hdmi", "home-assistant"]
authors = [
{ name = "Petr Vraník", email = "hpa@suteren.net" }
]
classifiers = [
"Development Status :: 4 - Beta",
"Topic :: Utilities",
"Topic :: Home Automation",
"Topic :: Multimedia",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = []

[project.scripts]
pycec = "pycec.__main__:main"

[project.urls]
Repository = "https://github.com/daptify14/pyCEC"
Upstream = "https://github.com/konikvranik/pyCEC"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["pycec"]

[tool.black]
line-length = 79
46 changes: 0 additions & 46 deletions setup.py

This file was deleted.

Loading