Skip to content

Commit

Permalink
Make instance variables explicit. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked authored Nov 9, 2023
1 parent fa5a1bf commit 219d6fa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.7.0a2: make instance variables explicit
0.7.0a1: support device/entity and standard integrations

0.6.3: restore switch state
Expand Down
2 changes: 1 addition & 1 deletion custom_components/momentary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .db import Db


__version__ = '0.7.0a1'
__version__ = '0.7.0a2'

_LOGGER = logging.getLogger(__name__)

Expand Down
12 changes: 5 additions & 7 deletions custom_components/momentary/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ class Db:
entries as needed.
"""

_group_name: str = None
_switches_file: str = DB_DEFAULT_SWITCHES_FILE
_switches = {}
_switches_meta_data = {}
_orphaned_switches = {}
_changed: bool = False

def __init__(self, group_name: str, file: str):
self._group_name = group_name
self._switches_file = file

self._switches = {}
self._switches_meta_data = {}
self._orphaned_switches = {}
self._changed: bool = False

def _make_original_unique_id(self, name):
if name.startswith("!"):
return slugify(name[1:])
Expand Down
2 changes: 1 addition & 1 deletion custom_components/momentary/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"dependencies": [],
"codeowners": ["@sherrell"],
"requirements": [],
"version": "0.7.0a1",
"version": "0.7.0a2",
"iot_class": "local_polling"
}
16 changes: 6 additions & 10 deletions custom_components/momentary/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ async def async_setup_entry(
class MomentarySwitch(RestoreEntity, SwitchEntity):
"""Representation of a Momentary switch."""

_uuid: str = ""
_mode: str = DEFAULT_MODE
_cancellable: bool = DEFAULT_CANCELLABLE
_toggle_for: timedelta = DEFAULT_TOGGLE_FOR
_toggle_until: datetime = DEFAULT_TOGGLE_UNTIL
_idle_state: bool = False
_timed_state: bool = True
_timer: Callable[[], None] | None = None
_hass = None

def __init__(self, uuid, config, hass):
"""Initialize the Momentary switch device."""

Expand All @@ -102,6 +92,12 @@ def __init__(self, uuid, config, hass):
self._toggle_for = config.get(CONF_TOGGLE_FOR, DEFAULT_TOGGLE_FOR)
self._cancellable = config.get(CONF_CANCELLABLE, DEFAULT_CANCELLABLE)

# Local defaults
self._toggle_until = DEFAULT_TOGGLE_UNTIL
self._idle_state = False
self._timed_state = True
self._timer = None

# Old configuration - only turns on
if self._mode.lower() == DEFAULT_MODE:
_LOGGER.debug(f'old config, idle-state={self._idle_state}')
Expand Down

0 comments on commit 219d6fa

Please sign in to comment.