diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index 9fbb030e96e..631650077ce 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -129,5 +129,8 @@ def _read(path): def _write(path, data): """Write YAML helper.""" + # Do it before opening file. If dump causes error it will now not + # truncate the file. + data = dump(data) with open(path, 'w', encoding='utf-8') as outfile: - outfile.write(dump(data)) + outfile.write(data) diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 57ea0351168..38e4fd18b28 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -393,8 +393,7 @@ class MQTT(object): self.progress = {} self.birth_message = birth_message self._mqttc = None - self._subscribe_lock = asyncio.Lock(loop=hass.loop) - self._publish_lock = asyncio.Lock(loop=hass.loop) + self._paho_lock = asyncio.Lock(loop=hass.loop) if protocol == PROTOCOL_31: proto = mqtt.MQTTv31 @@ -434,9 +433,10 @@ class MQTT(object): This method must be run in the event loop and returns a coroutine. """ - with (yield from self._publish_lock): + with (yield from self._paho_lock): yield from self.hass.loop.run_in_executor( None, self._mqttc.publish, topic, payload, qos, retain) + yield from asyncio.sleep(0, loop=self.hass.loop) @asyncio.coroutine def async_connect(self): @@ -484,9 +484,10 @@ class MQTT(object): if topic in self.topics: return - with (yield from self._subscribe_lock): + with (yield from self._paho_lock): result, mid = yield from self.hass.loop.run_in_executor( None, self._mqttc.subscribe, topic, qos) + yield from asyncio.sleep(0, loop=self.hass.loop) _raise_on_error(result) self.progress[mid] = topic diff --git a/homeassistant/const.py b/homeassistant/const.py index 6e9fe2f5d2b..3c93defc630 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -2,7 +2,7 @@ """Constants used by Home Assistant components.""" MAJOR_VERSION = 0 MINOR_VERSION = 39 -PATCH_VERSION = '0' +PATCH_VERSION = '1' __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 4, 2)