Skip to content

Commit

Permalink
Fix time delta import issue. (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked authored Nov 27, 2023
1 parent 627a541 commit 640469f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
0.9.0a4:
fix time delta import issue
0.9.0a3:
fix device tracker import issue
Slovakian translations, thanks @misa1515
Expand Down
4 changes: 2 additions & 2 deletions custom_components/virtual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .cfg import BlendedCfg, UpgradeCfg


__version__ = '0.9.0a2'
__version__ = '0.9.0a4'

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -174,7 +174,7 @@ async def async_virtual_set_availability_service(hass, call):
entity_id = call.data['entity_id']
value = call.data['value']

if not type(value)==bool:
if not type(value) == bool:
value = bool(util.strtobool(value))
domain = entity_id.split(".")[0]
_LOGGER.info("{} set_avilable(value={})".format(entity_id, value))
Expand Down
21 changes: 12 additions & 9 deletions custom_components/virtual/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
DB_LOCK = threading.Lock()


def _fix_value(value):
""" If needed, convert value into a type that can be stored in yaml.
"""
if isinstance(value, timedelta):
return max(value.seconds, 1)
return value


def _load_meta_data(group_name: str):
"""Read in meta data for a particular group.
"""
Expand Down Expand Up @@ -157,14 +165,6 @@ def _fix_config(config):
return entries


def _fix_value(value):
""" If needed, convert value into a type that can be stored in yaml.
"""
if isinstance(value, timedelta):
return max(value.seconds, 1)
return value


def _upgrade_name(name: str):
"""We're making the non virtual prefix the default so this flips the naming.
"""
Expand Down Expand Up @@ -197,6 +197,9 @@ def _parse_old_config(devices, configs, platform):
config[CONF_PLATFORM] = platform
config[CONF_NAME] = _upgrade_name(config[CONF_NAME])

# Fix values that need to be saved in yaml
config = {k: _fix_value(v) for k, v in config.items()}

# Insert or create a device for it.
if config[CONF_NAME] in devices:
devices[config[CONF_NAME]].append(config)
Expand Down Expand Up @@ -442,7 +445,7 @@ def import_yaml(config):
_save_meta_data(IMPORTED_GROUP_NAME, devices_meta_data)

@staticmethod
def create_flow_data(config):
def create_flow_data(_config):
""" Take the current aarlo config and make the new flow configuration.
"""
return {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/virtual/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"documentation": "https://github.com/twrecked/hass-virtual/blob/master/README.md",
"iot_class": "local_push",
"issue_tracker": "https://github.com/twrecked/hass-virtual/issues",
"version": "0.9.0a2"
"version": "0.9.0a4"
}

0 comments on commit 640469f

Please sign in to comment.