Moved code from ha outside hosts discovery